Skip to content


Using find_or_create_by

March 10, 2011

Rails comes with find_or_create_by to which something like name_and_description could be added so that the whole thing becomes:

Resource.find_or_create_by_name_and_description(“name”, “description”)

what this does is makes script to be reusable in the case it breaks in the middle. its a better way of writing a scirpct. if you would only use find then running the script again would create duplicate resource which is sometimes not desirable.



From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: