This post originated from an RSS feed registered with Ruby Buzz
by rwdaigle.
Original Post: What's New in Edge Rails: find_or_initialize_by_...
Feed Title: Ryan's Scraps
Feed URL: http://feeds.feedburner.com/RyansScraps
Feed Description: Ryan Daigle's various technically inclined rants along w/ the "What's new in Edge Rails" series.
Parallel to the find_or_create_by_X method that will find the requested model if it exists or create it and return it if it doesn’t is the new find_or_initialize_by_X which will find the requested model or create, but not save it, if it doesn’t exist.
The associated unit tests show us that an object initialized by this method is not yet saved to the database whereas the create version is: