rvm、ruby、rails をインストールした後、モデルに同じコード検証を記述します
class Item < ActiveRecord::Base
attr_accessible :name, :description, :price, :weight
validates :price, :weight, numericality: {greater_than: 0} , presence: true
end
しかし、レールコンソールを起動して印刷すると
tem1 = Item.create(name: "d", price: 0, weight: 1)
エラーがあります
Loading development environment (Rails 3.2.13)
2.0.0p0 :001 > item1 = Item.create(name: "d", price: 0, weight: 1)
NoMethodError: undefined method `validates' for #<Class:0x007ffa968ec810>
from /Users/epoleshchuk/RailsProject/test2/vendor/bundle/gems/activerecord-3.2.13/lib/active_record/dynamic_matchers.rb:55:in `method_missing'
from /Users/epoleshchuk/RailsProject/test2/app/models/item.rb:5:in `<class:Item>'
from /Users/epoleshchuk/RailsProject/test2/app/models/item.rb:1:in `<top (required)>'
from /Users/epoleshchuk/RailsProject/test2/vendor/bundle/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:469:in `load'
from /Users/epoleshchuk/RailsProject/test2/vendor/bundle/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:469:in `block in load_file'
from /Users/epoleshchuk/RailsProject/test2/vendor/bundle/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:639:in `new_constants_in'
from /Users/epoleshchuk/RailsProject/test2/vendor/bundle/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:468:in `load_file'
from /Users/epoleshchuk/RailsProject/test2/vendor/bundle/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:353:in `require_or_load'
from /Users/epoleshchuk/RailsProject/test2/vendor/bundle/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:502:in `load_missing_constant'
from /Users/epoleshchuk/RailsProject/test2/vendor/bundle/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:192:in `block in const_missing'
from /Users/epoleshchuk/RailsProject/test2/vendor/bundle/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:190:in `each'
from /Users/epoleshchuk/RailsProject/test2/vendor/bundle/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:190:in `const_missing'
from (irb):1
from /Users/epoleshchuk/RailsProject/test2/vendor/bundle/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
from /Users/epoleshchuk/RailsProject/test2/vendor/bundle/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
from /Users/epoleshchuk/RailsProject/test2/vendor/bundle/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from scexit
また、gem install activesupport -v 3.2.13 も役に立ちません。
Rails 3.2.13 ruby 2.0.0p0 (2013-02-24 リビジョン 39474) [x86_64-darwin12.3.0] rvm 1.19.3 (安定版)