Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you expose a controller as a resource, following actions are automatically added: </p> <pre><code>show index new create edit update destroy </code></pre> <p>These actions can be categorized in to two groups:</p> <ul> <li><code>:member</code> actions</li> </ul> <p>The URL for the member action has the id of the target resource. E.g: </p> <pre><code>users/1/edit users/1 </code></pre> <p>You can think of <code>:member</code> action as an instance method on a class. It always applies on an existing resource.</p> <p>Default member actions: <code>show</code>, <code>edit</code>, <code>update</code>, <code>destroy</code></p> <ul> <li><code>:collection</code> actions</li> </ul> <p>The URL for the <code>:collection</code> action does not contain the id of the target resource. E.g: </p> <pre><code>users/login users/register </code></pre> <p>You can think of <code>:collection</code> action as a static method on a class.</p> <p>Default collection actions: <code>index</code>, <code>new</code>, <code>create</code></p> <p>In your case you need two new actions for registration. These actions belong to :collection type( as you do not have the id of the user while submitting these actions). Your route can be as follows:</p> <pre><code>map.resources :users, :collection =&gt; { :signup =&gt; :get, :register =&gt; :post } </code></pre> <p>The URL for the actions are as follows:</p> <pre><code>users/signup users/register </code></pre> <p>If you want to remove a standard action generated by Rails use :except/:only options:</p> <pre><code>map.resources :foo, :only =&gt; :show map.resources :foo, :except =&gt; [:destroy, :show] </code></pre> <p><strong>Edit 1</strong></p> <p>I usually treat the <code>confirmation</code> action as a <code>:member</code> action. In this case <code>params[id]</code> will contain the confirmation code.</p> <p><strong>Route configuration:</strong></p> <pre><code>map.resources :users, :member =&gt; { :confirm =&gt; :get} </code></pre> <p><strong>URL</strong></p> <pre><code>/users/xab3454a/confirm confirm_user_path(:id =&gt; @user.confirmation_code) # returns the URL above </code></pre> <p><strong>Controller</strong></p> <pre><code>class UsersController &lt; ApplicationController def confirm # assuming you have an attribute called `confirmation_code` in `users` table # and you have added a uniq index on the column!! if User.find_by_confirmation_code(params[id]) # success else # error end end end </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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