我正在关注Rails guide以创建非常香草的验证。我已经创建了一个可以正常工作的回调,但是验证了:
class Group < ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection
validates :name, :presence => true
end
结果:
undefined method ` validates' for #<Class:0x007fa57b1a9e60>
这是带有以下gemfile的Rails 3.2.13
gem 'rails', '3.2.13'
gem 'pg'
group :assets do
gem 'sass-rails'
gem 'uglifier'
end
gem 'jquery-rails'
gem 'strong_parameters'
gem 'bootstrap-sass', '>= 2.3.0.0'
gem 'devise', '>= 2.2.3'
gem 'cancan', '>= 1.6.9'
gem 'omniauth'
gem 'omniauth-facebook'
gem 'paperclip', '~> 3.0'
gem 'friendly_id', "~> 4.0.9"
group :test, :development do
gem 'rspec-rails'
gem 'factory_girl_rails'
end
答案 0 :(得分:2)
使用validates_presence_of :name
。