Ruby on rails 未初始化的常量ActionController::RedirectBackError您的意思是什么?ActionController::RenderError
正在尝试实现Ruby on rails 未初始化的常量ActionController::RedirectBackError您的意思是什么?ActionController::RenderError,ruby-on-rails,ruby,rails-routing,Ruby On Rails,Ruby,Rails Routing,正在尝试实现重定向\u to:back方法 但我得到了一个错误: 未初始化的常量ActionController::RedirectBackError您的意思是什么?ActionController::RenderError my posts_controller.rb class PostsController
重定向\u to:back
方法
但我得到了一个错误:
未初始化的常量ActionController::RedirectBackError您的意思是什么?ActionController::RenderError
my posts_controller.rb
class PostsController 将_从ActionController::RedirectBackError中解救出来,使用::将_重定向到_默认值
def发布
post=post.find参数[:id]
发布!
重定向到:返回
结束
私有的
def重定向到默认值
将\重定向到根\路径
结束
结束
我的rails版本是:6.0.3.3
ruby版本:
ruby 2.7.1p83
dbugger是对的,您可能想试试这个:redirect\u back(fallback\u位置:根路径)
ActionController::RedirectBackError在Rails 6中不存在。查看Rails 5中引入的更新方式
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