当前位置: 动力学知识库 > 问答 > 编程问答 >

Why are Rails validations not working?

问题描述:

I'm following the Rails guide to create a very vanilla validation. I've created a callback that works fine, but the validates:

class Group < ActiveRecord::Base

include ActiveModel::ForbiddenAttributesProtection

validates :name, :presence => true

end

results in:

undefined method ` validates' for #<Class:0x007fa57b1a9e60>

This is Rails 3.2.13 with the following gemfile

source '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

网友答案:

Use validates_presence_of :name.

分享给朋友:
您可能感兴趣的文章:
随机阅读: