Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby routes and link_to, custom :action route problem
    primarykey
    data
    text
    <p>I'm trying to get this link:</p> <pre><code>&lt;%= link_to('Edit', :action =&gt; 'manage', :id =&gt; user) %&gt; </code></pre> <p>even tried explicitly &lt;%= link_to('Edit', {:controller => 'users', :action => 'manage', :id => user}, :method => :get) %></p> <p>to show the link in HTML as</p> <pre><code> '/users/manage/1' or '/users/1/manage' </code></pre> <p>but it shows up as </p> <pre><code>'/users/manage?id=1' </code></pre> <p>I can see in my routes:</p> <pre><code>manage_users GET /users/manage(.:format) {:action=&gt;"manage", :controller=&gt;"users"} ... edit_user GET /users/:id/edit(.:format) {:action=&gt;"edit", :controller=&gt;"users"} </code></pre> <p>so I added a <strong>map.connect</strong>, but it was added to <strong>users</strong></p> <pre><code>users GET /users/manage/:id(.:format) {:action=&gt;"manage", :controller=&gt;"users"} </code></pre> <p>but without any success. The link is still '/users/manage?id=1'</p> <p>This doesn't work anymore than the above.</p> <pre><code>GET /users/:id/manage(.:format) {:action=&gt;"manage", :controller=&gt;"users"} </code></pre> <p>Now, when I put the :action in link_to, to 'edit' i.e.</p> <pre><code>&lt;%= link_to('Edit', :action =&gt; 'edit', :id =&gt; user) %&gt; </code></pre> <p>The <strong>routes.rb edit_user GET /users/:id/edit/(.:format)</strong> works, with a link showing up of </p> <pre><code>'/users/1/edit' </code></pre> <p>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 <strong>'users/1/manage'</strong> instead of <strong>'/users/manage?id=1'</strong>??? Is it because my above <strong>map.connect</strong> is being added to <strong>users</strong>, when it should be added to <strong>'manage_users'</strong>?</p> <p>Thank for the help. I'll be trying to figure it out.</p> <p>Peace.</p> <p>BTW, <strong>/users/manage?id=1</strong> works, I just want the proper rewrite link to click on.</p> <p><em>EDIT</em> <strong>routes.rb</strong></p> <pre><code>map.resources :users, :collection =&gt; {:manage =&gt; :get} #map.manage_user '/users/:id/manage', :controller =&gt; :users, :action =&gt; :manage #map.resources :users, :member =&gt; { :manage =&gt; :get } #map.connect 'users/manage/:id(.:format)', :controller =&gt; 'users', :action =&gt; 'manage', :conditions =&gt; { :method =&gt; :get } map.resources :categories map.resources :posts map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload