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 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'') if @user.save redirect_to :list else render :action=>''createname'' end thanx in advance Pat --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Why would you get an error if you''re asking to find, and if it doesn''t exist, create? There should be no error. Jason On 2/2/07, Patrick Aljord <patcito-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > 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 > 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'') > > if @user.save > redirect_to :list > else > render :action=>''createname'' > end > > thanx in advance > > > Pat > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On 2/2/07, Jason Roelofs <jameskilton-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Why would you get an error if you''re asking to find, and if it doesn''t > exist, create? There should be no error. > > Jason > > > On 2/2/07, Patrick Aljord <patcito-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > 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 > > 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'') > > > > if @user.save > > redirect_to :list > > else > > render :action=>''createname'' > > end > > > > thanx in advance > > > > > > Pat > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---