Note that there are some explanatory texts on larger screens.

plurals
  1. PORails routes, problem with custom :action not being recognized, always 'show'
    primarykey
    data
    text
    <p>I'm trying to 'manage' users, instead of 'new' and 'show' users via actions. The problem is somewhere in routes I suspect, as my link '/users/manage' is being received as an id parameter to 'show' action:</p> <p>Terminal log of process:</p> <pre><code>Processing UsersController#show (for 127.0.0.1 at 2010-06-28 00:31:45) [GET] Parameters: {"id"=&gt;"manage"} ActionController::UnknownAction (No action responded to show. Actions: create, destroy, index, manage, and update): </code></pre> <p>Here are some <strong>code snippets</strong> of relevant parts:</p> <p><strong>users/index.html.erb</strong> (the link created to go to the manage section, i.e. '/users/manage'):</p> <pre><code>&lt;%= link_to('New User', :action =&gt; 'manage') %&gt; </code></pre> <p><strong>users_controller.rb</strong> (supposed to be receiving 'manage' action, but gets 'show' fr om above call:</p> <pre><code>def index @users = User.all respond_to do |format| format.html # index.html.erb format.xml { render :xml =&gt; @users } end end def manage @users = User.all @user = User.find(params[:id]) if params[:id] @user = User.new if @user.nil? respond_to do |format| format.html # new.html.erb format.xml { render :xml =&gt; @user } end end </code></pre> <p>Ruby/rails sees <strong>'/users/manage'</strong> as a <strong>':controller/:action/:id'</strong> i.e. <strong>'users/show/1'</strong>. </p> <p>When using <strong>'/users/manage/1'</strong> to edit a single user, the proper :action (as 'manage') is loaded via the UsersController 'manage' function, and everything is displayed to edit from the manage.html.erb file. UsersController sees 'manage' and not 'show', correctly, int his case, but only because of the :id being passed making the ':controller/:action/:id' route kick in and work.</p> <p><strong>'users/manage', :controller/:action</strong> seems to be the <strong>problem</strong>, <strong>not recognizing 'manage' as a valid :action alone, instead sending is as an :id in 'show'</strong>... </p> <p><strong>routes.rb</strong>:</p> <pre><code>ActionController::Routing::Routes.draw do |map| map.resources :users map.resources :categories map.resources :posts map.connect ':controller/:action' map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' end </code></pre> <p>Can someone please help me resolve this?</p> <p>Why is the 'show' action being automatically undertaken? Can I force 'users' and 'manage' in routes to be recognized in the controller as 'manage' and not as 'show'?</p> <p>Thanks for the help people :)</p> <p>Peace.</p> <p><em>EDIT</em> <strong>rake routes</strong></p> <pre><code>$ rake routes (in /home/krnel/sites/rails_projects/simple_blog) users GET /users(.:format) {:action=&gt;"index", :controller=&gt;"users"} POST /users(.:format) {:action=&gt;"create", :controller=&gt;"users"} new_user GET /users/new(.:format) {:action=&gt;"new", :controller=&gt;"users"} edit_user GET /users/:id/edit(.:format) {:action=&gt;"edit", :controller=&gt;"users"} user GET /users/:id(.:format) {:action=&gt;"show", :controller=&gt;"users"} PUT /users/:id(.:format) {:action=&gt;"update", :controller=&gt;"users"} DELETE /users/:id(.:format) {:action=&gt;"destroy", :controller=&gt;"users"} categories GET /categories(.:format) {:action=&gt;"index", :controller=&gt;"categories"} POST /categories(.:format) {:action=&gt;"create", :controller=&gt;"categories"} new_category GET /categories/new(.:format) {:action=&gt;"new", :controller=&gt;"categories"} edit_category GET /categories/:id/edit(.:format) {:action=&gt;"edit", :controller=&gt;"categories"} category GET /categories/:id(.:format) {:action=&gt;"show", :controller=&gt;"categories"} PUT /categories/:id(.:format) {:action=&gt;"update", :controller=&gt;"categories"} DELETE /categories/:id(.:format) {:action=&gt;"destroy", :controller=&gt;"categories"} posts GET /posts(.:format) {:action=&gt;"index", :controller=&gt;"posts"} POST /posts(.:format) {:action=&gt;"create", :controller=&gt;"posts"} new_post GET /posts/new(.:format) {:action=&gt;"new", :controller=&gt;"posts"} edit_post GET /posts/:id/edit(.:format) {:action=&gt;"edit", :controller=&gt;"posts"} post GET /posts/:id(.:format) {:action=&gt;"show", :controller=&gt;"posts"} PUT /posts/:id(.:format) {:action=&gt;"update", :controller=&gt;"posts"} DELETE /posts/:id(.:format) {:action=&gt;"destroy", :controller=&gt;"posts"} manage_users GET /users/manage(.:format) {:action=&gt;"manage", :controller=&gt;"users"} GET /users(.:format) {:action=&gt;"index", :controller=&gt;"users"} POST /users(.:format) {:action=&gt;"create", :controller=&gt;"users"} GET /users/new(.:format) {:action=&gt;"new", :controller=&gt;"users"} GET /users/:id/edit(.:format) {:action=&gt;"edit", :controller=&gt;"users"} GET /users/:id(.:format) {:action=&gt;"show", :controller=&gt;"users"} PUT /users/:id(.:format) {:action=&gt;"update", :controller=&gt;"users"} DELETE /users/:id(.:format) {:action=&gt;"destroy", :controller=&gt;"users"} /:controller/:action/:id /: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