Forum: Ruby on Rails routes.rb

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A0171c4f7c76cd1b895a5bfba8e2e122?d=identicon&s=25 Mark Moore (mrak)
on 2008-12-15 11:09
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
2d8132658d56e51f19ace1c68e48b6aa?d=identicon&s=25 Thorsten Mueller (thorsten)
on 2008-12-15 11:25
(Received via mailing list)
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
9b8d00f99fe595bdc45fd30439cf9c8f?d=identicon&s=25 Franz Strebel (Guest)
on 2008-12-15 11:27
(Received via mailing list)
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 topic is locked and can not be replied to.