在脚手架中使用保留的 Rails 字
我是 Rails 新手,但不是编程新手。我正在尝试创建一个案例管理应用程序,我正在运行命令
ruby script/generatescaffold Case casename:string caseid:string
这工作正常,但是因为 Case 是保留字,所以我尝试查看 localhost:3000/Cases 时出现错误
无论如何,还是我必须使用不同的名称?
提前致谢。
I'm new to rails, but not to programming. I'm trying to create a Case Management app, I'm running the command
ruby script/generate scaffold Case casename:string caseid:string
This works fine, however because Case is a reserved word I'm getting errors when trying to view localhost:3000/Cases
Is there anyway around this or do I just have to use a different name?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有些词是您无法解决的(见下文)。可能有一种方法可以解决“案例”问题,但通过更改名称会让您的生活更轻松。不要为小事担心 - 有很多真正的问题需要担心:-)
其他保留字 此处 和此处
祝你好运!
There are some words that you can't work around (see below). There may be a way to work around 'case' but you'll make life easier on yourself by changing the name. Don't sweat the small things - there're are plenty of real problems to worry about :-)
Other reserved words here and here
Good luck!
认为你会给自己带来比其价值更多的悲伤,就我个人而言,如果可能的话,我会避免使用保留字。
这些错误特定于使用单词
case
,因此如果您仍然愿意,可以将默认视图从: 更改为:
Think you are going to cause yourself more grief than it's worth, personally I would avoid reserved words if at all possible.
The errors are specific to using the word
case
, so if you still want to, you can make things work if you alter the default views from:to:
这是我看到的一个老问题,但我尝试使用这些单词的替代拼写。在此示例中,可以在案例后端使用“Kase”。另一个例子是“交易”的“Transaktion”。
至于在前端处理这个问题,内置的 i18n 支持 (http://guides.rubyonrails.org/ i18n.html)可能会让事情变得更容易。例如:
另外,我相信您可以在路由文件中使用一些技巧来修改所使用的 URL,但我之前没有测试过这些。
This is an old question I see, but I try to use alternate spellings of such words. In this example, "Kase" could be used on the backend for cases. Another example would be "Transaktion" for "transactions."
As for handling this on front end, the built-in i18n support (http://guides.rubyonrails.org/i18n.html) may make things easier. For example:
Also, I believe there are tricks you can use in the routes file to modify the URLs used, but I haven't tested any of this before.