Wednesday, October 7, 2009

[Rails] Re: Unique indexes

You could use find_or_create_by_note, too

2009/10/7, Marnen Laibow-Koser <rails-mailing-list@andreas-s.net>:
>
> Greg Donald wrote:
>> On Wed, Oct 7, 2009 at 8:15 AM, RVince <rvince99@hotmail.com> wrote:
>>> � � � �cnote.channel_id = @channel.id
>>> � � � �cnote.associate_id = current_associate.id
>>> � � � �g=cnote.save
>>
>> begin
>> cnote.save!
>> rescue
>> flash[:notice] = 'channel note failed to save'
>> end
>>
>> or you could check to see if it exists before trying to save it.
>>
>> cn = Channelnote.find_by_note( params[:channelnotes] )
>> cnote.save unless cn
>
> Or put a validates_uniqueness_of in the app.
>
>>
>>
>> --
>> Greg Donald
>> http://destiney.com/
>
>
> Best,
> --
> Marnen Laibow-Koser
> http://www.marnen.org
> marnen@marnen.org
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>

--
Von meinen Mobilgerät aus gesendet

--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate