2012-06-29 28 views

回答

3

你可以添加一个隐藏字段referring_pagesign_in - 形式的former引荐,即场和回路由添加到那里,如果其现有的,像这样:

def after_sign_in_path_for(resource) 
    params[:referring_page] || super 
end 

这是一个手动解决方案,但我把它更喜欢使用在控制器端复杂的逻辑。

1

我不明白你到底想要达到什么目的,说:“如果用户访问他们没有被授权查看的页面,他们会被重定向到登录页面。登录后他们被重定向到站点根目录”

我认为将会有两套用户之一是管理 - 用户和其他非管理员用户我处理这将是这样的方式,

内部应用控制器

class ApplicationController < ActionController::Base 
    protect_from_forgery 

    check_authorization :unless => :devise_controller? 
    before_filter :authenticate_user! 

    rescue_from CanCan::AccessDenied do |exception| 
    redirect_to root_url, :alert => exception.message 
    end 

    protected 

    def stored_location_for(resource_or_scope) 
    nil 
    end 

    def after_sign_in_path_for(resource_or_scope) 
    if current_user.admin? 
     #add your desired path 
    else 
     #redirect to your desired path 
    end 
    end 
end