Class: CabinetsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/cabinets_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
# File 'app/controllers/cabinets_controller.rb', line 22

def create
  @cabinet = Cabinet.new( cabinet_params )
  if @cabinet.save
    redirect_to new_cabinet_path, notice: 'Your changes were saved'
  else
    render :new, error: 'Sorry, your changes could not be saved'
  end
end

#destroyObject



41
42
43
44
45
# File 'app/controllers/cabinets_controller.rb', line 41

def destroy
  @cabinet = Cabinet.find(params[:id])
  @cabinet.destroy
  redirect_to cabinets_path, notice: 'Cabinet deleted'
end

#editObject



31
32
33
# File 'app/controllers/cabinets_controller.rb', line 31

def edit
  @cabinet = Cabinet.find(params[:id])
end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/cabinets_controller.rb', line 5

def index
  @cabinets = Cabinet.order('identifier')

  if params[:location]
    @cabinet_location = Location.find(params[:location])
    @cabinets = @cabinets.where(location_id: @cabinet_location.id) if @cabinet_location
  end

  if params[:identifier]
    @cabinets = @cabinets.where(identifier: params[:identifier])
  end
end

#newObject



18
19
20
# File 'app/controllers/cabinets_controller.rb', line 18

def new
  @cabinet = Cabinet.new
end

#updateObject



35
36
37
38
39
# File 'app/controllers/cabinets_controller.rb', line 35

def update
  @cabinet = Cabinet.find(params[:id])
  @cabinet.update_attributes( cabinet_params )
  redirect_to cabinets_path
end