title: Render to named path
body: <p>I have a rails project with the following route:</p>
  
  <pre><code>get 'login', to: 'user_sessions#new', as: :login
  </code></pre>
  
  <p>In my <code>UserSessionsController</code> I have</p>
  
  <pre><code>def create
     @user_session = UserSession.new(params[:user_session])
  
     respond_to do |format|
       if @user_session.save
         # Do all the happy stuff
       else
         format.html { render :action =&gt; 'new' }
         format.xml { render xml: @user_session.errors, status: :unprocessable_entity }
       end
     end
   end
  </code></pre>
  
  <p>That's working ok, except that when the user enters incorrect parameters the route is via <code>/user_sessions</code> instead of <code>/login</code>, which is untidy (and means my test assertions are confusing).</p>
  
  <p>Obviously I could just <code>redirect_to login_path</code>, but then my <code>@user_session.errors</code> don't seem to be available so by page doesn't show what was wrong.</p>
  
  <p>How do I redirect back to <code>/login</code> and still have the errors show?</p>
  
  <p>Edit:
  It looks as if Rails makes this difficult because it's something I shouldn't try to do. The RESTful path isn't really something the user cares about so I shouldn't be using it as part of my UI testing. Instead, I am looking at the actual content of the rendered page, which the user <em>does</em> care about. Thanks all.</p>