Created
August 2, 2012 19:15
-
-
Save cypriss/3239857 to your computer and use it in GitHub Desktop.
Working with associated models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This input set: | |
class Idea | |
class Create | |
include Command | |
required do | |
string :title, length: 100 | |
string :body | |
model :user, builder: User::CreateViaEmail, pk: true | |
end | |
end | |
end | |
# Allows this (passing in a valid, saved user): | |
Idea::Create.run(params, user: current_user) | |
# And this (finding by id): | |
Idea::Create.run(params, user: opts[:user_id]) | |
# And this (building from attributes): | |
Idea::Create.run(params, user: {email: opts[:email], name: opts[:name]}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment