Skip to content

Instantly share code, notes, and snippets.

@jeremyf jeremyf/gist:8959710
Created Feb 12, 2014

Embed
What would you like to do?
Thinking about how to model connecting a Group to a User
class Hydramata::Connection
include Virtus.model
include ActiveModel::Validations
extend ActiveModel::Naming
attribute :current_user, User
attribute :group_id, String
attribute :user_id, String
attribute :role, Sting
validates :role, inclusion: { ['manager', 'editor', 'soon?']}
def group
@group ||= Group.find(group_id)
end
def user
@user ||= User.find(user_id)
end
def save
valid? ? persist : false
end
private
def persist
group.add_member(user) && user.add_group(group)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.