1
votes

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'
2

2 Answers

1
votes

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.

0
votes

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) %>