I've just upgraded to Rails 4 and found an unexpected behaviour with routing.
We have a controller named EmailPreviewController. The routing for this was:
get "/emailpreview", controller: 'EmailPreview', action: :index
however after upgrading to Rails 4 this throws the following error when the environment is loaded:
'EmailPreview' is not a supported controller name. This can lead to potential routing problems. See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use
I've looked at the page it suggests however there isn't any indication that it's incorrect to use a controller with a CamelCase name.
If I change the controller to lower case there isn't any problem:
# this works fine
get "/emailpreview", controller: 'emailpreview', action: :index
Is this expected behaviour? Is it not possible to use camelcase controller names now or is there something else going on here?
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 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
.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With