Class: ImportsController
- Inherits:
-
ArtfullyOseController
- Object
- ActionController::Base
- ArtfullyOseController
- ImportsController
- Defined in:
- app/controllers/imports_controller.rb
Instance Method Summary collapse
- #approve ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #template ⇒ Object
Instance Method Details
#approve ⇒ Object
10 11 12 13 14 15 16 |
# File 'app/controllers/imports_controller.rb', line 10 def approve @import = organization.imports.find(params[:id]) @import.approve! flash[:notice] = "Your file has been entered in the import queue. This process may take some time. Reload this page to see progress or check back in a few minutes." redirect_to imports_path end |
#create ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/imports_controller.rb', line 41 def create @import = Import.build(@type) @import.user = current_user @import.organization = organization if @import.save redirect_to import_path(@import) else render :new end end |
#destroy ⇒ Object
53 54 55 56 57 |
# File 'app/controllers/imports_controller.rb', line 53 def destroy @import = organization.imports.find(params[:id]) @import.destroy redirect_to imports_path end |
#index ⇒ Object
6 7 8 |
# File 'app/controllers/imports_controller.rb', line 6 def index @imports = organization.imports.order('created_at desc').all end |
#new ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/imports_controller.rb', line 25 def new if params[:bucket].present? && params[:key].present? @import = Import.build(@type) @import.organization = organization @import.s3_bucket = params[:bucket] @import.s3_key = params[:key] @import.s3_etag = params[:etag] @import.status = "caching" @import.user_id = current_user.id @import.caching! redirect_to import_path(@import) else @import = Import.build(@type) end end |
#show ⇒ Object
18 19 20 21 22 23 |
# File 'app/controllers/imports_controller.rb', line 18 def show @import = organization.imports.find(params[:id]) @parsed_rows = @import.parsed_rows.paginate(:page => params[:page], :per_page => 50) @people = Person.where(:import_id => @import.id).paginate(:page => params[:page], :per_page => 50) unless @import.id.nil? end |
#template ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/imports_controller.rb', line 59 def template case @type when "events" fields = ParsedRow::EVENT_FIELDS when "people" fields = ParsedRow::PEOPLE_FIELDS when "donations" fields = ParsedRow::DONATION_FIELDS end columns = fields.map { |field, names| names.first } csv_string = CSV.generate { |csv| csv << columns } send_data csv_string, :filename => "Artfully-Import-Template.csv", :type => "text/csv", :disposition => "attachment" end |