# Validates\* gives me problems

**URL:** <https://www.ruby-forum.com/t/validates-gives-me-problems/59072>\
**Category:** Rails\
**Created:** [April 28, 2006, 11:59am UTC](https://www.ruby-forum.com/t/validates-gives-me-problems/59072 "2006-04-28T11:59:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![antoniorv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/90ced4/32.png) [@antoniorv](https://www.ruby-forum.com/u/antoniorv)\
**Post date:** [April 28, 2006, 11:59am UTC](https://www.ruby-forum.com/t/validates-gives-me-problems/59072/1 "2006-04-28T11:59:25Z")

</div>

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:in`validates\_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

---

<div class="post-metadata">

**Author:** ![antoniorv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/90ced4/32.png) [@antoniorv](https://www.ruby-forum.com/u/antoniorv)\
**Post date:** [April 28, 2006, 3:10pm UTC](https://www.ruby-forum.com/t/validates-gives-me-problems/59072/2 "2006-04-28T15:10:24Z")

</div>

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

> **[Planet Argon](https://www.planetargon.com)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[www.robbyonrails.com](http://www.robbyonrails.com)

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

---

<div class="post-metadata">

**Author:** ![antoniorv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/90ced4/32.png) [@antoniorv](https://www.ruby-forum.com/u/antoniorv)\
**Post date:** [May 2, 2006, 8:38pm UTC](https://www.ruby-forum.com/t/validates-gives-me-problems/59072/3 "2006-05-02T20:38:02Z")

</div>

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](http://www.planetargon.com)  
> [www.robbyonrails.com](http://www.robbyonrails.com)
> 
> +1 503 445 2457  
> +1 877 55 ARGON [toll free]  
> +1 815 642 4968 [fax]
