Displaying 1 result from an estimated 1 matches for "find_or_intialize_by_country_id".
2006 Oct 21
0
find_or_initialize_by and Nested Resources
...ource songs
end
To create a new song, the url would be:
/artists/:artist_id/songs/:song_id
However, lets say that an artist doesn''t exist yet. I only want to
create an artist if a new song by the artist is successfully saved. I
am retrieving the artist using something like:
@artist = find_or_intialize_by_country_id(@country)
Since the artist doesn''t exist yet, there will be no ''id'' attribute
yet. However, I have to pass in an id to the url which creates the
song, ie:
new_song_path(@artist)
This will obviously fail since @artist.id is nil. I can use
find_or_create_by instead, bu...