title: Rails devise if session sign_in error, then redirect to some page (back)
body: <p>How can i change standart devise session_controller, so that if, for example i entered incorrect password i'm redirected :back (is not required), and see my error's...</p>
  
  <p>For what i need this? Becouse i have my login only in template which is rendered in layout left block on all pages, and i didn't have new action-view...</p>
  
  <p><em>So how to do error's redirect to other page with validation message errors... ?</em></p>
  
  <p>Here is standart session_controller (now i didn't create it one, it is "nested"):</p>
  
  <pre><code>class Devise::SessionsController &lt; DeviseController
    prepend_before_filter :require_no_authentication, :only =&gt; [ :new, :create ]
    prepend_before_filter :allow_params_authentication!, :only =&gt; :create
    prepend_before_filter { request.env["devise.skip_timeout"] = true }
  
    # GET /resource/sign_in
    def new
      self.resource = build_resource(nil, :unsafe =&gt; true)
      clean_up_passwords(resource)
      respond_with(resource, serialize_options(resource))
    end
  
    # POST /resource/sign_in
    def create
      self.resource = warden.authenticate!(auth_options)
      set_flash_message(:notice, :signed_in) if is_navigational_format?
      sign_in(resource_name, resource)
      respond_with resource, :location =&gt; after_sign_in_path_for(resource)
    end
  
    # DELETE /resource/sign_out
    def destroy
      redirect_path = after_sign_out_path_for(resource_name)
      signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
      set_flash_message :notice, :signed_out if signed_out &amp;&amp; is_navigational_format?
  
      # We actually need to hardcode this as Rails default responder doesn't
      # support returning empty response on GET request
      respond_to do |format|
        format.all { head :no_content }
        format.any(*navigational_formats) { redirect_to redirect_path }
      end
    end
  
    protected
  
    def serialize_options(resource)
      methods = resource_class.authentication_keys.dup
      methods = methods.keys if methods.is_a?(Hash)
      methods &lt;&lt; :password if resource.respond_to?(:password)
      { :methods =&gt; methods, :only =&gt; [:password] }
    end
  
    def auth_options
      { :scope =&gt; resource_name, :recall =&gt; "#{controller_path}#new" }
    end
  end
  </code></pre>
  
  <p>also method in appcontroller</p>
  
  <pre><code>def after_sign_in_path_for(resource)      
      case resource
        when User then 
          user = User.find(current_user.id)
          total_markup_for_user = user.groups.map(&amp;:markup).sum
          if current_cart.present?
            cart_id = current_cart.id
          else
            cart_id = nil
          end
          ***
          end
          if request.referrer.to_s.include? "users"
            root_path
          else
            request.referrer 
          end
        when Admin::Admin then :admin_mainpage
      end
    end
  </code></pre>