Class: IshManager::EventsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ish_manager/events_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#basic_auth, #home, #tinymce

Instance Method Details

#createObject



4
5
6
7
8
9
10
11
12
13
14
# File 'app/controllers/ish_manager/events_controller.rb', line 4

def create
  authorize! :manage, Ish::Event
  @event = Ish::Event.create( params[:event].permit! )
  if @event.persisted?
    flash[:notice] = "Success."
    redirect_to action: 'index'
  else
    flash[:alert] = "No luck: #{@event.errors.full_messages.join(', ')}."
    render 'new'
  end
end

#editObject



16
17
18
19
# File 'app/controllers/ish_manager/events_controller.rb', line 16

def edit
  authorize! :manage, Ish::Event
  @event = Ish::Event.find params[:id]
end

#indexObject



21
22
23
24
25
26
27
# File 'app/controllers/ish_manager/events_controller.rb', line 21

def index
  authorize! :manage, Ish::Event
  @events = Ish::Event.all.order_by({ start_at: :desc })
  if params[:q]
    @events = @events.where({ :name => /#{params[:q]}/i })
  end
end

#newObject



29
30
31
32
# File 'app/controllers/ish_manager/events_controller.rb', line 29

def new
  authorize! :manage, Ish::Event
  @event = Ish::Event.new
end

#showObject



34
35
36
37
# File 'app/controllers/ish_manager/events_controller.rb', line 34

def show
  authorize! :manage, Ish::Event
  @event = Ish::Event.find params[:id]
end

#updateObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/ish_manager/events_controller.rb', line 39

def update
  authorize! :manage, Ish::Event
  @event = Ish::Event.find params[:id]
  @event.update_attributes( params[:event].permit! )
  if @event.persisted?
    flash[:notice] = "Success."
    redirect_to action: 'index'
  else
    flash[:alert] = "No luck: #{@event.errors.full_messages.join(', ')}."
    render 'edit'
  end
end