Jua*_*njo 55 redirect login ruby-on-rails devise
我发现的所有问题都与帮助者成功登录有关
after_sign_in_path_for(resource)
我在网站的索引中有一个登录表单,当登录失败时,它会重定向到"users/sign_in"
但是,当登录失败时,如何重定向到我的"site #index"?
小智 93
在lib目录中创建custom_failure.rb,其中包含:
class CustomFailure < Devise::FailureApp
def redirect_url
your_path
end
def respond
if http_auth?
http_auth
else
redirect
end
end
end
Run Code Online (Sandbox Code Playgroud)在您设计初始化程序时,包括:
config.warden do |manager|
manager.failure_app = CustomFailure
end
Run Code Online (Sandbox Code Playgroud)确保Rails在您的application.rb中的lib文件中加载:
config.autoload_paths += %W(#{config.root}/lib)
Run Code Online (Sandbox Code Playgroud)不要忘记重新启动服务器.
我认为没有更简单的方法来做到这一点.祝好运.
Sib*_*ang 14
如果您使用自己的SessionsController,您可以重新分配:recall值,auth_options以便controller#method在运行前调用您想要的值warden.authenticate!(auth_options),例如:
在app/controllers/users/sessions_controller.rb中
class Users::SessionsController < Devise::SessionsController
#...
def create
#...
auth_options = { :recall => 'site#index', :scope => :user }
resource = warden.authenticate!(auth_options)
#...
end
#...
end
Run Code Online (Sandbox Code Playgroud)
通过这种方式,您无需创建自定义的FailureApp并修改配置.
您可以更改默认登录路径。
查看https://github.com/plataformatec/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes
| 归档时间: |
|
| 查看次数: |
27210 次 |
| 最近记录: |