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.
Instance Method Details
#create ⇒ Object
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 |
#destroy ⇒ Object
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 |
#edit ⇒ Object
GET /sources/1/edit
51 52 53 |
# File 'app/controllers/calagator/sources_controller.rb', line 51 def edit @source = Source.find(params[:id]) end |
#import ⇒ Object
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. } } format.xml { render xml: @importer.source.errors, status: :unprocessable_entity } end end end |
#index ⇒ Object
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 |
#new ⇒ Object
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 |
#show ⇒ Object
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 |
#update ⇒ Object
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 |