Forum: Ruby on Rails validates* gives me problems

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Antonio R. (Guest)
on 2006-04-28 13:59
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
Robby R. (Guest)
on 2006-04-28 17:10
(Received via mailing list)
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.planetargon.com
www.robbyonrails.com

+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4968 [fax]
Antonio R. (Guest)
on 2006-05-02 22:38
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]
This topic is locked and can not be replied to.