Rails g 脚手架系列名称:字符串 - 这是命名约定错误还是其他原因

发布于 2024-11-19 12:45:36 字数 471 浏览 1 评论 0原文

在我的博客上,我有属于一个系列的帖子。我尝试过搭建系列,但路线存在一些问题。

复数引擎不正确,所以我不得不手动更改 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

总以为 2024-11-26 12:45:36

作为记录,我将奇异化代码放入了脚手架生成器中(是的,这是我对 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 calls record_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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文