Skip to content

Instantly share code, notes, and snippets.

@donnykurnia
Created April 20, 2012 11:22
Show Gist options
  • Save donnykurnia/2427868 to your computer and use it in GitHub Desktop.
Save donnykurnia/2427868 to your computer and use it in GitHub Desktop.
find or create parent object from children association
def autosave_associated_records_for_team
if team.name.blank?
self.team_id = 1
else
# Find or create the team by name
self.team = Team.find_or_create_by_name(team.name)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment