RyanW
RyanW

Reputation: 5398

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

Upvotes: 1

Views: 1028

Answers (1)

thank_you
thank_you

Reputation: 11107

Use validates_presence_of :name.

Upvotes: 2

Related Questions