问题描述
尝试实现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)