Skip to content

Instantly share code, notes, and snippets.

@andyh
Last active December 11, 2015 20:48
Show Gist options
  • Save andyh/4657426 to your computer and use it in GitHub Desktop.
Save andyh/4657426 to your computer and use it in GitHub Desktop.
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