Hum*_*eer 3 ruby ruby-on-rails rbenv ruby-on-rails-6 ruby-3
最近我将我的应用程序从 Ruby 版本 2.6.1 更新到 3.0.1 并且我使用 rbenv 作为版本管理器。
但是当我尝试运行 Rails 服务器时出现错误
=> Booting Puma
=> Rails 6.1.3 application starting in development
=> Run `bin/rails server --help` for more startup options
Exiting
/home/humayun/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.3/lib/active_support/rescuable.rb:56:in `rescue_from': Need a handler. Pass the with: keyword argument or provide a block. (ArgumentError)
from /home/humayun/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/will_paginate-3.1.8/lib/will_paginate/railtie.rb:67:in `rescue_from'
from /home/humayun/umerfarooq/Alchemy/app/controllers/application_controller.rb:2:in `<class:ApplicationController>'
from /home/humayun/umerfarooq/Alchemy/app/controllers/application_controller.rb:1:in `<main>'
Run Code Online (Sandbox Code Playgroud)
我刚刚阅读了有关导致第 56 行错误的函数的信息。
应用程序控制器.rb
rescue_from Exception, with: :handle_exception
protect_from_forgery prepend: true, with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
before_action :initialize_api
def not_found
raise ActionController::RoutingError.new('Not Found')
end
def handle_exception(exception = nil)
return render_404 if [ActionController::RoutingError, ActiveRecord::RecordNotFound].include?(exception.class)
render_500
end
Run Code Online (Sandbox Code Playgroud)
我认为这是因为折旧。
谁能告诉我如何处理这些错误?
你的handle_exception可能需要一个渲染视图或返回状态的块
正如错误中提到的,app/controllers/application_controller.rb:2您可能有一个rescue_from没有错误或处理程序,您需要遵循以下任何语法
class ApplicationController < ActionController::Base
rescue_from User::NotAuthorized, with: :deny_access # self defined exception
rescue_from ActiveRecord::RecordInvalid, with: :show_errors
rescue_from 'MyAppError::Base' do |exception|
render xml: exception, status: 500
end
private
def deny_access
...
end
def show_errors(exception)
exception.record.new_record? ? ...
end
end
Run Code Online (Sandbox Code Playgroud)
根据此处的文档https://apidock.com/rails/ActiveSupport/Rescuable/ClassMethods/rescue_from
- - - -更新:
这是由于will_paginate您使用的 gem 覆盖了rescue_from 控制器中的方法,同时新的 ruby 更新改变了关键字属性的行为
如果您的基本控制器include ControllerRescuePatch您可能能够将其删除,这将修复它,但不确定您的分页会发生什么。否则,请推迟 ruby 更新,直到will_paginate更新其代码来解决此问题
| 归档时间: |
|
| 查看次数: |
1263 次 |
| 最近记录: |