Skip to content

Instantly share code, notes, and snippets.

@Martin91
Created June 23, 2014 16:21
Show Gist options
  • Save Martin91/d1d19f0017f379e73eb5 to your computer and use it in GitHub Desktop.
Save Martin91/d1d19f0017f379e73eb5 to your computer and use it in GitHub Desktop.
habtm: collection.build doesn't build join associations (unlike collection.create)
@user = User.first
@project = @user.projects.build(:name => "Make your bed")
# if you do @project.save here, as in the gist,
# association will not be saved, but if you do :
@user.save
# it will save the @user with its associated projects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment