Note that there are some explanatory texts on larger screens.

plurals
  1. POcustom action in rails 3
    primarykey
    data
    text
    <p>I'm trying to make a simple link that will toggle my "status" attribute in my model from "pending" to "active". For example, when I first create a user, I set the status to "pending". Then when I show the list of users, I add a button that should change that user's status to "active". I tried this via a custom action (is this a good approach?) but I'm having trouble with the auto-generated named route. </p> <p>in my user index.html.haml: <code>button_to "Manually Activate", activate_user_path</code></p> <p>in routes.rb:</p> <pre><code>resources :users do get :activate, :on =&gt; :member </code></pre> <p>in users_controller.rb:<br></p> <pre><code> def activate @user = User.find(params[:id]) @user.update_attribute(:status, 'Active') redirect_to @user end </code></pre> <p>this seems to work when I go to say, /users/1/activate, as the status will update. However, the /users page doesn't show and gives me error: </p> <pre><code>ActionController::RoutingError in Users#index No route matches {:action=&gt;"activate", :controller=&gt;"users"} </code></pre> <p>ie, it is having a problem with the activate_user_path I specified in my view. (However if I use another named-routes-style path that I haven't specified in my routes.rb to test it out, I get</p> <pre><code>NameError in Users#index undefined local variable or method `blahblah_user_url' for #&lt;#&lt;Class:0x00000102bd5d50&gt;:0x00000102bb9588&gt; </code></pre> <p>so it seems that it knows it's in the routes.rb but something else is wrong? I'm really new to rails and would appreciate the help! thanks!</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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