Class: LocationsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- LocationsController
- Defined in:
- app/controllers/locations_controller.rb
Instance Method Summary collapse
-
#destroy ⇒ Object
CRUD ===========================================================================================.
- #edit ⇒ Object
-
#export ⇒ Object
Custom =========================================================================================.
- #import ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
- #upload ⇒ Object
Instance Method Details
#destroy ⇒ Object
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 |
#edit ⇒ Object
37 38 |
# File 'app/controllers/locations_controller.rb', line 37 def edit end |
#export ⇒ Object
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 |
#import ⇒ Object
13 14 |
# File 'app/controllers/locations_controller.rb', line 13 def import end |
#index ⇒ Object
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 |
#new ⇒ Object
44 45 46 |
# File 'app/controllers/locations_controller.rb', line 44 def new @location = Location.new end |
#show ⇒ Object
48 49 |
# File 'app/controllers/locations_controller.rb', line 48 def show end |
#update ⇒ Object
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 |
#upload ⇒ Object
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 |