Skip to content

Instantly share code, notes, and snippets.

@nfriend21
Created September 9, 2012 04:40
Show Gist options
  • Save nfriend21/3682635 to your computer and use it in GitHub Desktop.
Save nfriend21/3682635 to your computer and use it in GitHub Desktop.
class CompaniesController < ApplicationController
before_filter :authorize, :except => [:new]
def index
@companies = Company.all
end
def new
@company = Company.new
@company.users.build
end
def edit
@company = Company.find(params[:id])
end
def create
@company = Company.create(params[:company])
if @company.save
#session[:user_id] = @user.id #once user account has been created, a session is not automatically created. This fixes that by setting their session id. This could be put into Controller action to clean up duplication.
flash[:success] = "Your account has been created!"
redirect_to companies_path
else
render 'new'
end
end
def update
@company = Company.find(params[:id])
if @company.update_attributes(params[:company])
flash[:success] = " Your Company has been updated"
redirect_to @company
else
render 'edit'
end
end
def show
@company = Company.find(params[:id])
#company[:company_id] = @company.id
@tasks = @company.tasks
end
def destroy
@company = Company.find(params[:id])
@company.destroy
flash[:success] = "The Company has been deleted."
redirect_to companies_path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment