I am upgrading a routes.rb file from Rails 2.3 to Rails 4.
I've been able to upgrade each section's syntax by doing a lot of research. I'm at a resource block I'm trying to upgrade. The current Rails 2 syntax is below:
map.resources :profiles do |profile|
...
profile.resources :messages,
:requirements => { :profile_id => /[a-zA-Z0-9\-\_\.\@]+/ }
end
...
end
How do I convert :requirements => {...}
to Rails 4?
requirements
are now called constraints
. Your example should become
resources :messages, :constraints => { :profile_id => /[a-zA-Z0-9\-\_\.\@]+/ }
You should also be able to do
constraints :profile_id => /[a-zA-Z0-9\-\_\.\@]+/ do
resources :messages
end
which can be more legible