Sha256: 350c323c7de891beb4892ee37cc801b237e1959a054a858f40169006b615bb80

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

class Admin::CalendarsController < Admin::ApplicationController

  add_breadcrumb "Events", :admin_list_spud_calendar_events_path

  belongs_to_spud_app :events

  respond_to :html, :xml, :json, :js

  def new
    @page_name = "New Calendar"
    @calendar = SpudCalendar.new
    respond_with(@calendar)
  end

  def create
    @calendar = SpudCalendar.new(calendar_params)
    if @calendar.save
      redirect_to admin_list_spud_calendar_events_path
    else
      render :action => "new"
    end
  end

  def edit
    @page_name = "Edit Calendar"
    @calendar = SpudCalendar.find(params[:id])
    respond_with(@calendar)
  end

  def update
    @calendar = SpudCalendar.find(params[:id])
    if @calendar.update_attributes(calendar_params)
      flash[:notice] = 'Calendar was successfully updated.'
      redirect_to admin_list_spud_calendar_events_path
    else
      render :action => "edit"
    end
  end

  def destroy
    @calendar = SpudCalendar.find(params[:id])
    @calendar.spud_calendar_events.each do |event|
      event.update_attribute(:spud_calendar_id, 0)
    end
    @calendar.destroy
    respond_with(@calendar) do |format|
      format.js { render(:nothing => true) }
    end
  end

private

  def calendar_params
    params.require(:spud_calendar).permit(:title, :color)
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tb_events-1.1.2 app/controllers/admin/calendars_controller.rb
tb_events-1.1.1 app/controllers/admin/calendars_controller.rb
tb_events-1.1.0 app/controllers/admin/calendars_controller.rb