Class: Admin::AnnouncementsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/admin/announcements_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
# File 'app/controllers/admin/announcements_controller.rb', line 17

def create
  @announcement = Announcement.new(announcement_params)
  if @announcement.save
    redirect_to admin_announcements_path, :flash => { notice: 'Announcement created'}
  else
    render "new"
  end
end

#destroyObject



36
37
38
39
# File 'app/controllers/admin/announcements_controller.rb', line 36

def destroy
  @announcement.destroy
  redirect_to admin_announcements_path, :flash => { notice: 'Announcement deleted' }
end

#editObject



14
15
# File 'app/controllers/admin/announcements_controller.rb', line 14

def edit
end

#indexObject



6
7
8
# File 'app/controllers/admin/announcements_controller.rb', line 6

def index
  @announcements = AnnouncementFinder.for_admin
end

#newObject



10
11
12
# File 'app/controllers/admin/announcements_controller.rb', line 10

def new
  @announcement = Announcement.new_with_defaults
end

#updateObject



26
27
28
29
30
31
32
33
34
# File 'app/controllers/admin/announcements_controller.rb', line 26

def update
  @announcement.attributes = announcement_params
  @announcement.roles = [] unless announcement_params.has_key?(:roles)  
  if @announcement.save
    redirect_to admin_announcements_path, :flash => { notice: 'Announcement updated' }
  else
    render "edit"
  end
end