简体   繁体   中英

Ruby on Rails: Gemfile Issue

I want date validation, so I added the date_validator gem.

I very simply entered the command:

gem install date_validator

And then I was able to add the relevant part to my model, and everything worked as expected -- invalid dates were rejected.

However, I also tried adding this gem to my Gemfile, which creates the following error:

/var/www/html/redmine-2.6.5/lib/redmine/core_ext/active_record.rb:42:in `<top (required)>': DateValidator is not a class (TypeError)

Why does this happen? I don't understand...the gem works fine -- removing the gem from the Gemfile causes everything to work perfectly. So why would merely adding it to the Gemfile cause problems??

Here's my Gemfile:

source 'https://rubygems.org'


gem "will_paginate", "3.1.0" 
gem "nested_form", "0.3.2"
gem "date_validator", "0.9.0"
gem "rails", "3.2.21"
gem "jquery-rails", "~> 3.1.1"
gem "coderay", "~> 1.1.0"
...
...

I am not familiar with redmine but something like this happening with you.

2.2.0 :022 >   module Me
2.2.0 :023?>   end
 => nil 
2.2.0 :024 > class Me
2.2.0 :025?>   end
TypeError: Me is not a class
    from (irb):24

date_validator gem have module with name 'DateValidator' https://github.com/codegram/date_validator/blob/master/lib/date_validator.rb

And redmine gem have class with name 'DateValidator' https://github.com/redmine/redmine/blob/master/lib/redmine/core_ext/active_record.rb

In your case, date_validator gem is loading properly and creating module but redmine fails to define class with same name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM