未初始化的常量ActionController :: RedirectBackError您的意思是? ActionController :: RenderError

问题描述

尝试实现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

解决方法

调试器是正确的,您可能想尝试以下方法:redirect_back(fallback_location: root_path)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...