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

标签 ruby-on-rails ruby model-view-controller devise ruby-on-rails-4

我已经尝试过 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/

相关文章:

html - 如何将我的前端开发人员构建的 HTML 页面添加到 Rails 元素中?

ruby-on-rails - 如何迭代多个数组并在每第 n 次迭代后添加异常?

ruby-on-rails - 启动从 ubuntu 上的 ruby​​ gem 下载的 postgres 服务器

ruby - Rspec `eq` 与 `eql` 测试中的 `expect`

ruby-on-rails - Autoprefixer 不支持 Node v0.10.37 错误

ruby-on-rails - bin/rails 生成模型 文章标题 :string text:text

ruby - 浮点正则表达式?

javascript - 基于 Controller 命名空间约定延迟加载外部 JS/CSS 文件?

ios - 如何在 Swift Xcode 8.2 中以编程方式将导航 Controller 嵌入到选项卡栏 Controller 中?

c# - 在 ASP.NET MVC 中发送项目集合