ruby 需要一个接头人通过:关键字参数或提供块

ny6fqffe  于 12个月前  发布在  Ruby
关注(0)|答案(2)|浏览(99)

最近我将我的应用程序从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>'

我刚刚读了Here关于导致第56行错误的函数。
applciation_controller.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

我认为这是因为贬值。
有谁能告诉我如何处理这些错误吗?

5m1hhzi4

5m1hhzi41#

您的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

根据此处的文档https://apidock.com/rails/ActiveSupport/Rescuable/ClassMethods/rescue_from
-更新
这是由于您正在使用的will_paginate gem覆盖了控制器中的rescue_from方法,以及新的ruby更新更改了关键字属性的行为
如果你的基本控制器include ControllerRescuePatch你可能可以删除它,这将修复它,但不确定会发生什么事,你的分页。否则,推迟ruby更新,直到will_paginate更新他们的代码来修复这个问题。

628mspwn

628mspwn2#

我只是试着使用will_paginategem的最新版本,它对我很有效。

gem 'will_paginate', '~> 4.0'

相关问题