Skip to content

Instantly share code, notes, and snippets.

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

Embed
What would you like to do?
Group Membership spit-balling
class GroupMembershipForm
include Virtus.model
include ActiveModel::Validations
extend ActiveModel::Naming
attributes :group_id, String
attributes :members, Array[MembershipRole]
validates :group_id, presence: true
def save
valid? ? persist : false
end
private
def persist
members.each do |member|
GroupMembership.create(
group_id: group_id,
user_id: member.user_id,
role: member.role
)
end
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.