Last active
December 11, 2015 20:48
-
-
Save andyh/4657426 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AccountsController < ApplicationController | |
load_and_authorize_resource | |
# do not need to be logged in for :new or :create | |
skip_before_filter :authorize_user, only: [:new, :create] | |
def new | |
@account.users.build | |
@account.offices.build | |
@account.phone_numbers.build | |
end | |
def create | |
# first user will always be an admin | |
@account.users.first.role = 'admin' | |
# first phone number will always be an office number | |
@account.phone_numbers.first.subtype = 'office' | |
if @account.save | |
user = @account.users.first | |
session[:user_id] = user.id | |
redirect_to dashboard_path | |
else | |
render action: 'new' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment