Automatically create an object if it doesn't exist?

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?

On Dec 2, 2006, at 15:40 , empath wrote:

I want an action that will take a url like

Foo.com

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 S. - http://mentalized.net