title: Why redirecting to #show action without passing the :id param work (in rails)?
body: <p>I have a simple question about rails.</p>
  
  <p>I followed a tutorial (from CrashLearner).
  In that tutorial we have a simple resource <code>message</code> that generates the regular following routes (excerpt from <code>rake routes</code>)</p>
  
  <pre><code>      Prefix Verb   URI Pattern                  Controller#Action
      messages GET    /messages(.:format)          messages#index
               POST   /messages(.:format)          messages#create
   new_message GET    /messages/new(.:format)      messages#new
  edit_message GET    /messages/:id/edit(.:format) messages#edit
       message GET    /messages/:id(.:format)      messages#show
               PATCH  /messages/:id(.:format)      messages#update
               PUT    /messages/:id(.:format)      messages#update
               DELETE /messages/:id(.:format)      messages#destroy
  </code></pre>
  
  <p>As I understand the route to get to the <code>show</code> action of this controller is like something <code>/messages/17</code>, I mean we have to put the <code>:id</code> of that particular message we want to view.</p>
  
  <p>So, if I needed to redirect the user to this message view after he modified it (in the <code>#update</code> action) I should use:</p>
  
  <pre><code>redirect_to message_path(17)
  </code></pre>
  
  <p>But it turns out that omitting this <code>:id</code> actually works great:</p>
  
  <pre><code>redirect_to message_path
  </code></pre>
  
  <p>Why and how this last one work ?</p>
  
  <p>Since this works from an action that actually <em>received</em> the <code>:id</code> param I suppose that the controller keep it in memory and pass it through by default under the hood when it is missing but I would like to understand where this behavior come from ?</p>
  
  <p>I found nothing in the rails documentation.</p>
  
  <p>Here is the github repository of the tutorial, so the exact specific place of the above line is <a href="https://github.com/CrashLearner/ESPN/blob/master/app/controllers/messages_controller.rb#L30" rel="nofollow noreferrer">here in this controller</a>.</p>
  
  <p>And I confirm that this works.</p>
  
  <p>There is also a <code>Comment</code> resource that is nested from the previous <code>Message</code> resource.
  As you can see <a href="https://github.com/CrashLearner/ESPN/blob/master/app/controllers/comments_controller.rb#L22" rel="nofollow noreferrer">in that controller on the <code>update</code> action</a>, after updating a comment (which is nested within a message) the controller redirects to the <code>message_path</code> but in that case the <code>:id</code> parameter is present through the instance variable <code>@message</code> <em>(and I learned that this works because the object <code>Message</code> respond to an <code>.id</code> method otherwise it should be <code>@message.id</code>)</em></p>
  
  <p>I supposed that the reason that why here the <code>:id</code> is still passed is because we are in the <code>Comments</code> controller and the <code>:id</code> of another resource could not be passed under the hood, thus why it is explicitely written.</p>
  
  <p>I don't have another explication..</p>
  
  <p>Can anyone explain me why this works ?</p>