class LocationsController < ApplicationController before_filter :authenticate_user!, :only => [:destroy, :edit, :export, :import, :index, :new, :update, :upload] if Object.const_defined?('Devise') before_filter :scope_location, :only => [:show, :edit, :update, :destroy] # Custom ========================================================================================= 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 def import end 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 * '
').html_safe end flash[:notice] = 'File has been uploaded successfully.' unless flash[:error] redirect_to locations_path end end # CRUD =========================================================================================== def destroy @location.destroy flash[:notice] = 'Deleted location.' redirect_to locations_path end def edit end def index @locations = Location.all.order_by([params[:by] || :name, params[:dir] || :asc]) end def new @location = Location.new end def show end def update if @location.update_attributes(params[:location]) flash[:notice] = 'Updated location.' redirect_to locations_path else render :action => 'edit' end end private def scope_location @location = Location.find(params[:id]) end end