Class: LocationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/locations_controller.rb

Instance Method Summary collapse

Instance Method Details

#destroyObject

CRUD ===========================================================================================



31
32
33
34
35
# File 'app/controllers/locations_controller.rb', line 31

def destroy
  @location.destroy
  flash[:notice] = 'Deleted location.'
  redirect_to locations_path
end

#editObject



37
38
# File 'app/controllers/locations_controller.rb', line 37

def edit
end

#exportObject

Custom =========================================================================================



6
7
8
9
10
11
# File 'app/controllers/locations_controller.rb', line 6

def export
  headers["Content-Type"] = "application/x-excel"
  headers["Content-disposition"] = %{attachment; filename="locations.xls"}
  @locations = Location.all
  self.response_body = render :layout => false
end

#importObject



13
14
# File 'app/controllers/locations_controller.rb', line 13

def import
end

#indexObject



40
41
42
# File 'app/controllers/locations_controller.rb', line 40

def index
  @locations = Location.all.order_by([params[:by] || :name, params[:dir] || :asc])
end

#newObject



44
45
46
# File 'app/controllers/locations_controller.rb', line 44

def new
  @location = Location.new
end

#showObject



48
49
# File 'app/controllers/locations_controller.rb', line 48

def show
end

#updateObject



51
52
53
54
55
56
57
58
# File 'app/controllers/locations_controller.rb', line 51

def update
  if @location.update_attributes(params[:location])
    flash[:notice] = 'Updated location.'
    redirect_to locations_path
  else
    render :action => 'edit'
  end
end

#uploadObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/locations_controller.rb', line 16

def upload
  if params[:upload].blank?
    flash[:error] = 'You must choose an import file.'
    render :action => 'import'
  else
    unless (errors = LocationImport.save(params[:upload])).blank?
      flash[:error] = (errors * '<br />').html_safe
    end

    flash[:notice] = 'File has been uploaded successfully.' unless flash[:error]
    redirect_to locations_path
  end
end