Sha256: 7a203dba94ee78d6f5bec0a273593d67b134bd8d645f311bbdb3eff40dd0d6b7

Contents?: true

Size: 1.27 KB

Versions: 6

Compression:

Stored size: 1.27 KB

Contents

class EventsController < ApplicationController
  include Polygallery::StrongParams
  before_filter :fetch_event, :only => [:show, :edit, :update, :destroy]

  def new
    @event = Event.new
    @event.build_first_photos
  end

  def create
    @event = Event.new event_params
    if @event.save
      flash[:success] = 'Your event has been saved!'
    else
      flash[:error] = 'Your event could not be saved!'
    end
    # redirect_to event_path(@event)
    redirect_to root_path
  end

  def index
    @events = Event.includes(:gallery => [:photos]).order(:updated_at => :desc)
  end

  def show
  end

  def edit
  end

  def update
    if @event.update_attributes event_params
      flash[:success] = 'Your event has been saved!'
    else
      flash[:error] = 'Your event could not be saved!'
    end
    redirect_to event_path(@event)
  end

  def destroy
    if @event.destroy
      flash[:success] = 'Your event has been deleted!'
    else
      flash[:error] = 'Your event could not be deleted!'
    end
    redirect_to events_path
  end

  private
  def event_params
    params.require(:event).permit(:title, :gallery_attributes => polygallery_params, :custom_gallery_attributes => polygallery_params('custom_photos'))
  end
  def fetch_event
    @event = Event.find(params[:id])
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
polygallery-0.2.1 test/dummy/app/controllers/events_controller.rb
polygallery-0.1.9 test/dummy/app/controllers/events_controller.rb
polygallery-0.1.8 test/dummy/app/controllers/events_controller.rb
polygallery-0.1.7 test/dummy/app/controllers/events_controller.rb
polygallery-0.1.6 test/dummy/app/controllers/events_controller.rb
polygallery-0.1.4 test/dummy/app/controllers/events_controller.rb