gpt4 book ai didi

ruby-on-rails - 更新后设计更改重定向

转载 作者:行者123 更新时间:2023-12-04 14:34:55 25 4
gpt4 key购买 nike

我已经尝试过 Devise 的 github 上的代码。在我的应用程序 Controller 中,我有:

after_filter :store_location

def store_location
# store last url - this is needed for post-login redirect to whatever the user last visited.
if (request.fullpath != "/users/sign_in" &&
request.fullpath != "/users/sign_up" &&
request.fullpath != "/users/password" )
session[:previous_url] = request.fullpath
puts 'stores location'
end
end

def after_update_path_for(resource)
session[:previous_url] || dashboard_path
puts 'after update'
end

当我检查我的服务器时,会出现 store_location 方法中的 puts 语句,但 after_update_path_for 中的 puts 语句没有出现。如何让 after_update_redirect 工作?

这是设计所说的,但它不起作用:

https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-in,-sign-out,-sign-up,-update

最佳答案

从文档:

(Object) after_update_path_for(resource) (protected)
The default url to be used after updating a resource. You need to overwrite this method in your own RegistrationsController.



所以创建你的 ow RegistrationsController 是正确的。不过,这是一个更简单的解决方案:
after_update_path_for电话 signed_in_root_path(resource)哪个看起来像家 #{scope}_root_path .这里的范围通常是 user (但如果不是,您可能知道它是什么)。在“用户”的情况下,实现 user_root_path在您的应用程序 Controller 中,返回您的 dashboard_url , 应该管用。
def user_root_path
dashboard_url
end

虽然一开始对我来说似乎有点骇人听闻,但我相信它很“好”;用户范围的根路径确实可能是仪表板页面。

关于ruby-on-rails - 更新后设计更改重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21169393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com