【发布时间】: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
【问题讨论】:
-
ActionController::RedirectBackError 在 Rails 6 中不存在。查看 Rails 5 中引入的更新方式blog.bigbinary.com/2016/02/29/…
标签: ruby-on-rails ruby rails-routing