Validates* gives me problems

Hi,

In Debian/testing (mysql-5.0.20, ruby1.8, rails 1.1.0)

Im trying to follow up the fourdaysonrails tutorial, and when putting:

validates_uniqueness_of :category, :message => “Already exists”

in /myapplication/app/model/category.rb

I get:

NoMethodError in Categories#create

undefined method `category’ for #Article:0x407f6418

RAILS_ROOT: /var/www/audio/public/…/config/…
Application Trace | Framework Trace | Full Trace

#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/base.rb:1786:in
method_missing' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:300:invalidates_each’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:299:in
`validates_each’
.
.
.
Don’t know what i’m doing wrong

Cheers,

Antonio

On Apr 28, 2006, at 2:59 AM, antonio rv wrote:

I get:

NoMethodError in Categories#create

undefined method `category’ for #Article:0x407f6418

What are the attributes of your Category model?

it should be something like:

class Category < ActiveRecord::Base
validates_uniqueness_of :name, :message => ‘already exists’

end

So that… its testing on that specific attribute. You don’t test on
the whole object to be unique with validates_uniqueness_of.

-Robby

Robby R.
Founder & Executive Director

PLANET ARGON, LLC
Ruby on Rails Development, Consulting & Hosting

www.robbyonrails.com

+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4968 [fax]

Robby R. wrote:

On Apr 28, 2006, at 2:59 AM, antonio rv wrote:

I get:

NoMethodError in Categories#create

undefined method `category’ for #Article:0x407f6418

What are the attributes of your Category model?

it should be something like:

class Category < ActiveRecord::Base
validates_uniqueness_of :name, :message => ‘already exists’

end

Hi Robby,

My Category model looking as this one:

class Categoria < ActiveRecord::Base
end

works fine, but allowing duplicate entries or void ones. If I modify the
model to look as this other one:
class Categoria < ActiveRecord::Base

validates_uniqueness_of :category, :message => “already exists”

end

I get all the stuff posted in my previous message:

NoMethodError in Categoria#create

undefined method `category’ for #Categoria:0x40873454

RAILS_ROOT: /var/www/audio/public/…/config/…
Application Trace | Framework Trace | Full Trace

#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/base.rb:1786:in
method_missing' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:300:in validates_each’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:299:in
`validates_each’

Bla, bla…

My database is this one:

audio, with tables: articulos, categorias

Some idea?

Cheers,

Antonio

So that… its testing on that specific attribute. You don’t test on
the whole object to be unique with validates_uniqueness_of.

-Robby

Robby R.
Founder & Executive Director

PLANET ARGON, LLC
Ruby on Rails Development, Consulting & Hosting

www.planetargon.com
www.robbyonrails.com

+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4968 [fax]