views:

37

answers:

2

Hello,

I'm trying to get this link:

<%= link_to('Edit', :action => 'manage', :id => user) %>

even tried explicitly <%= link_to('Edit', {:controller => 'users', :action => 'manage', :id => user}, :method => :get) %>

to show the link in HTML as

 '/users/manage/1' or '/users/1/manage'

but it shows up as

'/users/manage?id=1'

I can see in my routes:

manage_users GET    /users/manage(.:format)            {:action=>"manage", :controller=>"users"}
...
edit_user GET    /users/:id/edit(.:format)          {:action=>"edit", :controller=>"users"}

so I added a map.connect, but it was added to users

users    GET    /users/manage/:id(.:format)        {:action=>"manage", :controller=>"users"}

but without any success. The link is still '/users/manage?id=1'

This doesn't work anymore than the above.

GET    /users/:id/manage(.:format)        {:action=>"manage", :controller=>"users"}

Now, when I put the :action in link_to, to 'edit' i.e.

<%= link_to('Edit', :action => 'edit', :id => user) %>

The routes.rb edit_user GET /users/:id/edit/(.:format) works, with a link showing up of

'/users/1/edit'

How do I get my link_to to show the same link when it is 'manage' instead of 'edit', i.e. showing a link of 'users/1/manage' instead of '/users/manage?id=1'??? Is it because my above map.connect is being added to users, when it should be added to 'manage_users'?

Thank for the help. I'll be trying to figure it out.

Peace.

BTW, /users/manage?id=1 works, I just want the proper rewrite link to click on.

EDIT routes.rb

map.resources :users, :collection => {:manage => :get}

#map.manage_user '/users/:id/manage', :controller => :users, :action => :manage
#map.resources :users, :member => { :manage  => :get } 
#map.connect 'users/manage/:id(.:format)', :controller => 'users', :action => 'manage',  :conditions => { :method => :get }

map.resources :categories
map.resources :posts
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
A: 

so I added a map.connect, but it was added to users
I suspect you added map.connect after other definitions, which would give it lowest priority. Try putting it in the beginning of routes.rb file.

You can also use named routes to avoid confusion:

map.manage_user '/users/:id/manage', :controller => :users, :action => :manage

and then refer it as

link_to 'Manage', manage_user_path(:id => user)

edit
If that doesn't work, please show your routes.rb file.

Nikita Rybak
I added a map to get the manage_user and not user section for GET: **map.resources :users, :member => { :manage => :get }** giving **manage_user GET /users/:id/manage(.:format) {:action=>"manage", :controller=>"users"}** but still the same 'manage?id=1' link. Will try your suggestion.
KrNel
WOOPS. Forgot the second part of your post, the link_to. It works! Thanks!!!! Hmmmm... pretty complicated stuff eheheheh
KrNel
**<%= link_to('Edit', manage_user_path(:id => user)) %>** + EITHER( **map.resources :users, :member => { :manage => :get }** OR **map.manage_user '/users/:id/manage', :controller => :users, :action => :manage** ) = **'/users/1/manage'**. Thanks again Nikita.
KrNel
To clear up: the problem was in the 'link_to' creation, and the 'manage_user' route not being made.
KrNel
A: 

You should change collection to member in your routes.rb when defining map.resources :users. Then you'll get nice /users/1/manage link.

Also, when creating a link try this:

<%= link_to 'Manage', manage_user_path(user) %>
Eimantas
No, that's for another thing, both with and without :id need work (single --member-- and plural --collection--). Thanks for the comment though :), yup the link_to needs the path from resource.map.resources :users, :collection => {:manage => :get} and map.resources :users, :member => { :manage => :get }
KrNel