将用户从登录页面重定向到登录Rails并与Devise

问题描述:

我希望我的用户在他们登录后访问“/ users/sign_in”后将其重定向到主页。我该怎么做?将用户从登录页面重定向到登录Rails并与Devise

在你的控制器动作的登录页面(注册可能,如果你使用的是色器件)。如果您还没有,则必须重写控制器。

def new  
    if current_user 
    redirect_to home_page_url 
    else 
    #current logic for sign in method (super) if you currently don't have it implemented 
    end 
end 

以下内容添加到您的routes.rb:

match "user_root", :to => "site#show" # where SiteController#show is your home page 

我也从router.rb文件中发现了一种这样做的方法;这要比从路由器上做起来容易得多,这要求我重写设备控制器。

authenticated :admin do 
    root :to => 'admin/dashboard#show' 
    end 

    authenticated do 
    root :to => 'dashboard#show' 
    end 

    root :to => 'landing#show' 

http://rubydoc.info/github/plataformatec/devise/master/ActionDispatch/Routing/Mapper:authenticated