module Jobshop class Registration < VirtualRecord memo_attr(:user) { team.users.build(user_params) } memo_attr(:team) { record = Jobshop::Team.find(params[:team_id]) record.assign_attributes(team_params) record } def save return false unless valid? result = ActiveRecord::Base.transaction do user.save! team.update!(owner: user, registration_token: nil, registration_token_sent_at: nil) end result != false end private def registration_params params.fetch(:registration, ActionController::Parameters.new) end def team_params registration_params.fetch( :team, ActionController::Parameters.new).permit(:name) end def user_params registration_params.fetch(:user, ActionController::Parameters.new). permit(:email, :password, :password_confirmation) end end end