Routes.rb

Hi,

I am going through a tutorial in a rails book. I have Something off with
routes:
I have RESTful resource in routes.rb:

“…
map.resources :users, :member => { :enable => :put } do |users|
users.resources :roles
end
…”

and in a html.erb partial I have:
“…
<%= link_to ‘assign role’,
role_url(:id => role.id, :user_id => @user.id),
:method => :put %>
…”
I get:
NoMethodError in Roles#index

Showing roles/_role.html.erb where line #9 raised:

undefined method `role_url’ for #ActionView::Base:0x3637bdc

I might be using newer version of rails than the book. The role_url is
not an explicitly defined route in this tutorial routes.rb file, I don’t
know enough about RoR, but I am guessing the role_url should be
automatically available, so I would appreciate any help with this
because my RoR learning is halted here.
Cheers,
Mark

If you nest your resources as you do, then
the url will need all parts of it like:

user_role_path(@user, role)

As parameters it takes the resource ids as default,
so you don’t need the :id and the :user_id here

and don’t forget that you can use rake routes to see all your
available routes at any given time, and their corresponding
controllers and actions.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs