Routing for controllers with multiple words in in Rails 4

这一生的挚爱 提交于 2019-12-05 04:52:52

The answer to this was somewhat counter-intuitive. I assume it's as-designed but it's not what I would have expected.

In Rails 3, you could specify controllers using the object's name

In Rails 3, you could pass the name of the controller object and Rails would find its way to it:

get "emailpreview", controller: 'EmailPreview', action: :index

would find its way to the EmailPreviewController contained within email_preview.rb.

however in Rails 4 you need to pass controller names in snake-case

In Rails 4 it seems that you need to pass the name of the controller object in snake-case:

get "emailpreview", controller: 'email_preview', action: :index

This will make its way to the EmailPreviewController contained within email_preview.rb.

Also see http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing (though this doesn't explain much in this particular instance)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!