Class: Calagator::SourcesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Calagator::SourcesController
- Defined in:
- app/controllers/calagator/sources_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /sources POST /sources.xml.
-
#destroy ⇒ Object
DELETE /sources/1 DELETE /sources/1.xml.
-
#edit ⇒ Object
GET /sources/1/edit.
-
#import ⇒ Object
POST /import POST /import.xml.
-
#index ⇒ Object
GET /sources GET /sources.xml.
-
#new ⇒ Object
GET /sources/new.
-
#show ⇒ Object
GET /sources/1 GET /sources/1.xml.
-
#update ⇒ Object
PUT /sources/1 PUT /sources/1.xml.
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
POST /sources POST /sources.xml
58 59 60 61 |
# File 'app/controllers/calagator/sources_controller.rb', line 58 def create @source = Source.new create_or_update end |
#destroy ⇒ Object
DELETE /sources/1 DELETE /sources/1.xml
85 86 87 88 89 90 91 92 93 |
# File 'app/controllers/calagator/sources_controller.rb', line 85 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 |
#edit ⇒ Object
GET /sources/1/edit
52 53 54 |
# File 'app/controllers/calagator/sources_controller.rb', line 52 def edit @source = Source.find(params[:id]) end |
#import ⇒ Object
POST /import POST /import.xml
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/calagator/sources_controller.rb', line 7 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. } } format.xml { render xml: @importer.source.errors, status: :unprocessable_entity } end end end |
#index ⇒ Object
GET /sources GET /sources.xml
23 24 25 26 27 28 29 30 |
# File 'app/controllers/calagator/sources_controller.rb', line 23 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 |
#new ⇒ Object
GET /sources/new
46 47 48 49 |
# File 'app/controllers/calagator/sources_controller.rb', line 46 def new @source = Source.new @source.url = params[:url] if params[:url].present? end |
#show ⇒ Object
GET /sources/1 GET /sources/1.xml
34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/calagator/sources_controller.rb', line 34 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 => e flash[:failure] = e.to_s if params[:id] != 'import' redirect_to new_source_path end |
#update ⇒ Object
PUT /sources/1 PUT /sources/1.xml
65 66 67 68 |
# File 'app/controllers/calagator/sources_controller.rb', line 65 def update @source = Source.find(params[:id]) create_or_update end |