I want an action that will take a url like foo.com/?bar=baz and check to see if baz exists, and if not, create a new one with bar=baz. This seems like it should be simple, but I just can''t figure it out. I''ve got the part that redirects to showing the item if it exists, but I can''t for the life of me figure out how to redirect this to a create method (which would require using POST instead of GET). any ideas? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jakob Skjerning
2006-Dec-03 12:52 UTC
Re: [POSSIBLE SPAM] [Rails] automatically create an object if it doesn''t exist?
On Dec 2, 2006, at 15:40 , empath wrote:> I want an action that will take a url like > > foo.com/?bar=baz > > and check to see if baz exists, and if not, create a new one with > bar=baz.No need to redirect, just do your business in the action: item = Item.find_or_create_by_name(params[:bar]) -- Jakob Skjerning - http://mentalized.net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---