/
companies_controller.rb
51 lines (40 loc) · 998 Bytes
/
companies_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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 new; 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