Restful Authentication Action Controller:异常捕获问题

时间:2009-11-14 11:21:21

标签: ruby-on-rails

当登录失败时,它会重定向到会话路径,并且我发现异常捕获错误并且显示

  

未知操作未执行任何操作   节目。行动:accessdenied,   checkroles,create,destroy,new,   renderoptionalerrorfile,   角色要求,和   role_requirements =

sessions_controller

def new
      end

      def create
        logout_keeping_session!
        user = User.authenticate(params[:login], params[:password])
        if user
          # Protects against session fixation attacks, causes request forgery
          # protection if user resubmits an earlier form using back
          # button. Uncomment if you understand the tradeoffs.
          # reset_session
          self.current_user = user
          new_cookie_flag = (params[:remember_me] == "1")
          handle_remember_cookie! new_cookie_flag
          redirect_back_or_default('/')
          flash[:notice] = "Logged in successfully"
        else
          note_failed_signin
          @login       = params[:login]
          @remember_me = params[:remember_me]
          render :action => 'new'
        end
      end
protected
  # Track failed login attempts
  def note_failed_signin
    flash[:error] = "Couldn't log you in as '#{params[:login]}'"
    logger.warn "Failed login for '#{params[:login]}' from #{request.remote_ip} at #{Time.now.utc}"
  end
end

路由

  map.logout '/logout', :controller => 'sessions', :action => 'destroy'
  map.login '/login', :controller => 'sessions', :action => 'new'
  map.register '/register', :controller => 'users', :action => 'create'
  map.signup '/signup', :controller => 'users', :action => 'new'
  map.resources :users

  map.resource :session

1 个答案:

答案 0 :(得分:0)

你试过redirect_to而不是渲染吗?

进一步检查后,这可能与您的map.resource电话有关。使用单数map.resource(而不是复数)时,不会为index创建默认路由。

您可能需要rake:routes查看可用的路线,并查看map.resource here的信息。