【问题标题】:uninitialized constant ActionController::RedirectBackError Did you mean? ActionController::RenderError未初始化的常量 ActionController::RedirectBackError 您的意思是? ActionController::RenderError
【发布时间】:2020-10-02 13:58:46
【问题描述】:

尝试实现redirect_to :back方法 但我收到了这个错误:

uninitialized constant ActionController::RedirectBackError Did you mean? ActionController::RenderError

我的 posts_controller.rb

class PostsController < ApplicationController
  rescue_from ActionController::RedirectBackError, with: :redirect_to_default

  def publish
    post = Post.find params[:id]
    post.publish!
    redirect_to :back
  end

  private

  def redirect_to_default
    redirect_to root_path
  end
end

我的 Rails 版本是:6.0.3.3 和红宝石版本:ruby 2.7.1p83

【问题讨论】:

标签: ruby-on-rails ruby rails-routing


【解决方案1】:

dbugger 是对的,你可能想试试这个:redirect_back(fallback_location: root_path)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-04
    • 2013-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-16
    • 2016-01-19
    相关资源
    最近更新 更多