Sha256: c13cc281d365c5c596689dbccadc10255d6790cb5ec6100e8110333d5cebd437

Contents?: true

Size: 1.43 KB

Versions: 14

Compression:

Stored size: 1.43 KB

Contents

class LinksController < EventCalendar::ApplicationController  
  private
    def event
      @event ||= Event.find(params[:event_id])
    end
    def link
      @link ||= if params[:id].present?
                  Link.find(params[:id])
                else
                  event.links.build(params[:link])
                end
    end
    def load_resources
      event
      link
    end
    def redirect_to_event
      redirect_to event_path params[:event_id]
    end
    def respond(&block)
      respond_to do |format|
        format.html{ yield }
        format.js
      end
    end
  protected
  public
    def new
      load_resources
    end
    def show
      load_resources
    end
    def edit
      load_resources
    end
    def update
      if link.update_attributes(params[:link])
        flash[:notice] = "Link successfully updated." unless request.xhr?
        event if request.xhr?
        respond{ redirect_to_event }
      else
        event
        respond{ render :edit and return }
      end
    end
    def create
      load_resources
      begin
        event.save!(:without_revision => true)
        flash[:notice] = "Link successfully created." unless request.xhr?
        respond{ redirect_to_event }
      rescue ActiveRecord::RecordInvalid
        respond{ render 'events/show' and return }
      end
    end
    def destroy
      link.destroy
      flash[:notice] = "Link successfully deleted."
      redirect_to_event
    end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
event_calendar_engine-0.2.15 app/controllers/links_controller.rb
event_calendar_engine-0.2.14 app/controllers/links_controller.rb
event_calendar_engine-0.2.13 app/controllers/links_controller.rb
event_calendar_engine-0.2.11 app/controllers/links_controller.rb
event_calendar_engine-0.2.10 app/controllers/links_controller.rb
event_calendar_engine-0.2.8 app/controllers/links_controller.rb
event_calendar_engine-0.2.7 app/controllers/links_controller.rb
event_calendar_engine-0.2.6 app/controllers/links_controller.rb
event_calendar_engine-0.2.5 app/controllers/links_controller.rb
event_calendar_engine-0.2.4 app/controllers/links_controller.rb
event_calendar_engine-0.2.3 app/controllers/links_controller.rb
event_calendar_engine-0.2.2 app/controllers/links_controller.rb
event_calendar_engine-0.2.1 app/controllers/links_controller.rb
event_calendar_engine-0.2.0 app/controllers/links_controller.rb