I want user to work with only one order connected to user’s session. So I set singular resource for order
routes.rb:
resource :order
views/orders/new.html.erb:
<%= form_for @order do |f| %>
...
<% end %>
But when I open the new order page I get an error:
undefined method `orders_path`
I know, that I can set :url => order_path in form_for, but what is the true way of resolving this collision?
Unfortunately, this is a bug. You’ll have to set the url like you mention.
Note that this will properly route to
createorupdatedepending on whether@orderis persisted.Update
There’s another option now. You can add this to your routes config:
Then when the
polymorphic_urlmethod is given an object with class name "Order" it will use[:order]as the url component instead of callingmodel_name.route_keyas described in jskol’s answer.This has the limitation that it cannot be used within scopes or namespaces. You can route a namespaced model at the top level of the routes config:
But it won’t have an effect on routes with extra components, so