Class: Calagator::SourcesController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /sources POST /sources.xml



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

def create
  @source = Source.new
  create_or_update
end

#destroyObject

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



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

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



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

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

#importObject

POST /import POST /import.xml



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

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



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

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



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

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

#showObject

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



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

def show
  @source = Source.find(params[:id], include: [: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



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

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