Class: Calagator::SourcesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#recaptcha_enabled?

Instance Method Details

#createObject

POST /sources POST /sources.xml



56
57
58
59
# File 'app/controllers/calagator/sources_controller.rb', line 56

def create
  @source = Source.new
  create_or_update
end

#destroyObject

DELETE /sources/1 DELETE /sources/1.xml



83
84
85
86
87
88
89
90
91
# File 'app/controllers/calagator/sources_controller.rb', line 83

def destroy
  @source = Source.find(params[:id])
  @source.destroy

  respond_to do |format|
    format.html { redirect_to sources_url }
    format.xml  { head :ok }
  end
end

#editObject

GET /sources/1/edit



50
51
52
# File 'app/controllers/calagator/sources_controller.rb', line 50

def edit
  @source = Source.find(params[:id])
end

#importObject

POST /import POST /import.xml



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

def import
  @importer = Source::Importer.new(params.permit![:source])
  respond_to do |format|
    if @importer.import
      redirect_target = @importer.events.one? ? @importer.events.first : events_path
      format.html { redirect_to redirect_target, flash: { success: render_to_string(layout: false) } }
      format.xml  { render xml: @importer.source, events: @importer.events }
    else
      format.html { redirect_to new_source_path(url: @importer.source.url), flash: { failure: @importer.failure_message } }
      format.xml  { render xml: @importer.source.errors, status: :unprocessable_entity }
    end
  end
end

#indexObject

GET /sources GET /sources.xml



21
22
23
24
25
26
27
28
# File 'app/controllers/calagator/sources_controller.rb', line 21

def index
  @sources = Source.listing

  respond_to do |format|
    format.html { @sources = @sources.paginate(page: params[:page], per_page: params[:per_page]) }
    format.xml  { render xml: @sources }
  end
end

#newObject

GET /sources/new



44
45
46
47
# File 'app/controllers/calagator/sources_controller.rb', line 44

def new
  @source = Source.new
  @source.url = params[:url] if params[:url].present?
end

#showObject

GET /sources/1 GET /sources/1.xml



32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/calagator/sources_controller.rb', line 32

def show
  @source = Source.find(params[:id], include: %i[events venues])
  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render xml: @source }
  end
rescue ActiveRecord::RecordNotFound => error
  flash[:failure] = error.to_s if params[:id] != 'import'
  redirect_to new_source_path
end

#updateObject

PUT /sources/1 PUT /sources/1.xml



63
64
65
66
# File 'app/controllers/calagator/sources_controller.rb', line 63

def update
  @source = Source.find(params[:id])
  create_or_update
end