LoginSignup
0
0

More than 1 year has passed since last update.

uninitialized constant Grape::Validations::Base (NameError)が発生

Posted at

結論

grapeのバージョンv1.6.2 で grape-kaminariのバージョン0.4.1 を使うと
railsコマンド使用時にタイトルのエラーが発生する。

原因

grape-kaminari-0.4.1/lib/grape/kaminari/max_value_validator.rb
module Grape
  module Kaminari
    class MaxValueValidator < Grape::Validations::Base
      def validate_param!(attr_name, params)
        attr = params[attr_name]
        return unless attr.is_a?(Integer) && @option && attr > @option

        raise Grape::Exceptions::Validation.new(
          params: [@scope.full_name(attr_name)],
          message: "must be less than or equal #{@option}",
        )
      end
    end
  end
end

3行目の継承元が Grape::Validations::Base となっていること。

grapeのバージョンが1.5.3だと問題ないが
1.6.2だと
Grape::Validations::Validators::Base
としないといけなくなっている。

先ほどぶち当たった問題なので、急ぎ投稿しておく。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0