Rails g 脚手架系列名称:字符串 - 这是命名约定错误还是其他原因
在我的博客上,我有属于一个系列的帖子。我尝试过搭建系列,但路线存在一些问题。
复数引擎不正确,所以我不得不手动更改 Sery
、@series
和 @sery
,这没什么大不了的。
resources :series
的路由似乎没问题。但是当我尝试创建一个系列时,form_for
帮助程序抱怨该路线。
然后,当我用控制台创建它时,它可以工作,但 Rails 仍然抱怨路线。
请创建一个简单的应用程序并看看问题是什么。
rails new test_series_app
然后运行脚手架生成器:
rails g scaffold series name:string
看看路线是如何混淆的,请帮助我!
On my blog I'm have posts that belong to a series. I've tried to scaffold series but there are some problems with routes.
The pluralization engine doesn't get it right so I had to manually change Sery
, @series
, and @sery
which is not a big deal.
The routing seems to be ok with resources :series
. But then when I try to create a series the form_for
helper complains about the route.
And then when I create it with console it works but rails is still complaining about routes.
Please create a simple app and see what the problem is.
rails new test_series_app
And then run the scaffold generator:
rails g scaffold series name:string
And see how the routes are getting mixed up and help me out please!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为记录,我将奇异化代码放入了脚手架生成器中(是的,这是我对 Rails 的一个贡献)。它所做的只是检查
record_name == record_name.pluralize
。如果确实如此,并且您尚未传入--force-plural
,它会调用record_name = record_name.singularize
。在这种情况下,“series”.pluralize与“series”.singularize相同,所以我认为它不会做任何事情。
因此,如果您遇到问题,则需要为该单词编写一个变形器。
(我是在 Jeremy Kemper 2008 年 RailsConf 主题演讲之后写下这篇文章的,当时他不小心传入了复数模型名称,导致自己在演讲过程中陷入了各种悲伤。)
For the record, I put the singularize code into the scaffold generator (yes, my one contribution to Rails). All it does is check if
record_name == record_name.pluralize
. If it does and you haven't passed in--force-plural
, it callsrecord_name = record_name.singularize
.In this case "series".pluralize is the same as "series".singularize so I assume it won't do anything.
So if you're having problems w/ it, you need to write an inflector for the word.
(I wrote it after Jeremy Kemper's 2008 RailsConf keynote in which he accidentally passed in a plural model name causing himself all sorts of grief in the middle of his talk.)