railsはログイン後に元のページに戻ることを実現します(restful_authenticationプラグインで)


restful_authenticationプラグインアプリケーションでは、ユーザーがログインせずにページを閲覧できる機能を実現する場合があります.しかし、ユーザーが権限が必要なページにアクセスしようとすると、自動的にログインインタフェースにジャンプします.ユーザー登録が完了すると、ユーザー登録前に行きたいページに自動的にジャンプします.
restful_authenticationプラグインでは、このような機能を実現するにはsession_controller.rbでcreateメソッドを変更する

  def create
    #      
    self.current_user = User.authenticate(params[:login], params[:password])
    if logged_in?
      ...
#           ,     
      redirect_to(
        session[:return_to]
      )
      flash[:notice] = "    "
    else
#     
      render :action => 'new'
      flash[:notice] = "        "
    end
  end


もう一つ修正したいのはauthenticatedですsystem.rb中login_requiredメソッドとaccess_deniedメソッド.

    def login_required
#    "store_location"     
      store_location
      authorized? || access_denied
    end

 def access_denied
      respond_to do |format|
        format.html do
#    "store_location"   ,         
#          store_location
          redirect_to new_session_path
        end
        format.any do
          request_http_basic_authentication 'Web Password'
        end
      end
    end