On Wed, Oct 7, 2009 at 8:15 AM, RVince <[email protected]> wrote: > > > I have a unique index on Channelnote.note. > In my controller, I go to save the Channelnote. > But, if the note portion already exists, it naturally throws an error. > How can I alleviate this, so that it only saves if the note is NOT > already in the table? Thanks, RVince > > cnote = Channelnote.new > cnote.note = params['channelnotes'] > 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 -- Greg Donald http://destiney.com/ --~--~---------~--~----~------------~-------~--~----~ 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

