title: Passing data between controllers with the session RESTfully
body: <p>I'm using a <em>hideous</em> pattern in my code and I know there must be a better way to do this. Help me rethink what I'm doing.</p>
  
  <p>My website is a kind of discussion forum.  All replies to discussions are done on the DiscussionsController#show page, inline.</p>
  
  <p>Some replies are invalid, though - for example, if you try and post a reply that has no text in it, it returns you to DiscussionsController#show with an error message.</p>
  
  <p>Here's a brief outline of how I've implemented this workflow:</p>
  
  <ol>
  <li>User goes to DiscussionsController#show.  This template has a reply form on it.  There is no explicit RepliesController#new action.</li>
  <li>User submits reply form, which is POSTed to replies_path and handled in RepliesController#create.</li>
  <li>RepliesController#create is unable to save the reply because it's invalid (validates_length_of in Reply invalidates the object).</li>
  <li>RepliesController#create puts the reply object in session[:new_reply] and redirects to the discussion_path the user came from.</li>
  <li>DiscussionsController#show handles the session object...</li>
  </ol>
  
  <p>Like so:</p>
  
  <pre><code>if session[:new_reply]
    @new_reply = session[:new_reply]
    session.delete(:new_reply)
  end
  </code></pre>
  
  <p>And now show.html.erb has a newly-regenerated @new_reply object to inspect for errors.</p>
  
  <p>There's something obviously wrong with this - you shouldn't store entire objects inside of the session.  But since the Reply object we attempted to save in RepliesController#create is never saved, how do I persist it between controller action calls?</p>
  
  <p>Or if there's a larger design solution, feel free to share it.  This is so ugly it's hurting me.  Thanks.</p>