为什么Rails验证不起作用?

时间:2013-05-31 23:20:05

标签: ruby-on-rails validation activerecord ruby-on-rails-3.2

我正在关注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

来源'https://rubygems.org'

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

1 个答案:

答案 0 :(得分:2)

使用validates_presence_of :name