Skip to content

Commit

Permalink
companies controller modified
Browse files Browse the repository at this point in the history
  • Loading branch information
7akimz committed Jun 23, 2011
1 parent 79e7f3f commit 25a1139
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions app/controllers/companies_controller.rb
Expand Up @@ -2,31 +2,50 @@ class CompaniesController < ApplicationController

respond_to :html

before_filter :authenticate_user!
before_filter :authorized_user, :only => [:new, :create, :destroy]
before_filter :get_company, :except => [:index, :create]

def index

@companies = Company.all
end

def show

end
def show; end

def new

end
def new; end

def edit

end
def edit; end

def create

@company = Company.new(params[:company])

if @company.save
flash[:notice] = "New company is created"
respond_with(@company)
else
flash[:alert] = "Error!!"
render :new
end
end

def update

if @company.update_attributes(params[:company])
flash[:notice] = "Attributes has been updated!"
respond_with(@company)
else
render :edit
end
end

def destroy

@company.destroy
flash[:notice] = "Company deleted!!"
respond_with(@company)
end

private
def get_company
@company = params[:id].present? ? Company.find(params[:id]) :
Company.new
end
end

0 comments on commit 25a1139

Please sign in to comment.