title: Login from navbar, and stay on current page
body: <p>I've worked through Ruby on Rails Tutorial by Michael Hartl, and have also implemented a small login form included on the navbar of my application (so a user can either login from the actual login page or from the navbar login). If a user logs in from the login page, I do want them to be redireced to the root_url.</p>
  
  <p>However, if the user logs in from the navbar form, I want them to stay on the same page with a "Successfully logged in!" message at the top of the page. How can I do this?</p>
  
  <p>My code is as follows:</p>
  
  <p>From the <code>_header.html.erb</code> file:</p>
  
  <pre><code>&lt;%= form_tag sessions_path, class: "navbar-form pull-right" do %&gt;
    &lt;%= text_field_tag :email, nil, class: "input-small", placeholder: "Email" %&gt;
    &lt;%= password_field_tag :password, nil, class: "input-small", placeholder: "Password" %&gt;
    &lt;%= check_box_tag :remember_me, 1, params[:remember_me], title: "select to remember login" %&gt;
    &lt;%= submit_tag "Sign in", class: "btn btn-mini" %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>From the <code>sessions_helper.rb</code> file:</p>
  
  <pre><code>def redirect_back_or(default)
    redirect_to(session[:return_to] || default)
    session.delete(:return_to)
  end
  
  def store_location
    session[:return_to] = request.url
  end
  </code></pre>
  
  <p>I have tried to leverage the <code>redirect_back_or</code> method from the <code>sessions_helper.rb</code>, but it seems to be capturing a session path as the session[:return_to] value, rather than the originating page for the login request. I would appreciate your ideas.</p>