Okechi Onyeje f06c2ca057 Mutltiple database pattern for companies integrated
- When creating a new company as an admin, a new database containing models for Runs, Grades, Results, Machines, and Oysters is migrated and created
- When a user registers, they are automatically switched to their company's db in the server
- When a user signs in they are also automatically swithched
2017-02-16 12:34:29 -05:00

38 lines
832 B
Ruby

class RegistrationsController < Devise::RegistrationsController
include ApplicationHelper
#protected
def new
Apartment::Tenant.switch!
end
def create
@user = User.new(sign_up_params)
if params[:company_serial]
params.require(:user).permit(:company_id)
company = Company.find_by(company_token: params[:company_serial])
if company
@user.company_id = company.id
if company.company_name == "IVA"
@user.admin = true
end
else
end
else
end
@user.save
sign_in @user
if !@user.admin
Apartment::Tenant.switch(Company.find(@user.company_id).company_name.gsub(/'/,'').gsub(/\s/,''))
end
redirect_to "/"
end
def sign_up_params
params.require(:user).permit(:email, :password, :password_confirmation)
end
end