Forum: Ruby on Rails @errors issue

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
997433f165140d58f52b8c0d1d005dc1?d=identicon&s=25 Patrick Aljord (Guest)
on 2007-02-02 19:33
(Received via mailing list)
hey all,
I use validates_uniqueness_of :name.
In script/console when i do  find_or_create_by_name('bob') and that
bob already exists I get @errors=> name has already been taken
But in my createname.rhtml it doesn't display anything though I did
put  <%= error_messages_for :user %>.

this is my controller:

@user = find_or_create_by_name('bob')

redirect_to :list
render :action=>'createname'

thanx in advance

83ca41657a99b65d99889abe712ba5e2?d=identicon&s=25 Jason Roelofs (Guest)
on 2007-02-02 20:27
(Received via mailing list)
Why would you get an error if you're asking to find, and if it doesn't
exist, create? There should be no error.

997433f165140d58f52b8c0d1d005dc1?d=identicon&s=25 Patrick Aljord (Guest)
on 2007-02-02 23:18
(Received via mailing list)
well, if i put validates_uniqueness_of :name, then obviously even if I
use find_or_create I cannot create something that is a duplicate and
indeed it doesn't get created, the only problem is that I don't get
the error on the page though I do get the error in script/console
This topic is locked and can not be replied to.