module UserDeactivator extend self def call(user, active: active) return if user.active == active user.update! active: active user.posts.update_all active: active user.votes.update_all active: active user.comments.update_all active: active user.following_association.update_all active: active user.followers_association.update_all active: active end end
class RegistrationController < ApplicationController def create @registration = RegistrationForm.new(registration_params) if @registration.save redirect_to user_path(@registration.user) else render :new end end end
class RegistrationController < ApplicationController def create @registration = RegistrationForm.new(registration_params) @registration.save respond_with @registration end end
def update(attributes) attributes.each do |name, value| public_send "#{name}=", value end if valid? & user.update(user_attributes) && account.update(acco account.users << user AccountWasCreated.perform_later(account) else false end end private def ensure_unique_user_email errors.add :email, 'already taken' if User.where(email: email). end def ensure_unique_account_name errors.add :name, 'already taken' if Account.where(name: name). end
else false end end private def ensure_unique_user_email errors.add :email, 'already taken' if User.where(email: email). end def ensure_unique_account_name errors.add :name, 'already taken' if Account.where(name: name). end def user_attributes {first_name: first_name, last_name: last_name, email: email} end def account_attributes {plan: plan, name: name} end end