1

我正在按照Rails 指南创建一个非常普通的验证。我创建了一个工作正常的回调,但验证:

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
4

1 回答 1

2

使用validates_presence_of :name.

于 2013-06-01T00:10:33.097 回答