Class: Admin::SponsorsController

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

Overview

COPYRIGHT:

Copyright (c) 2005-2009 North Carolina State University
Developed with funding for the National eXtension Initiative.

LICENSE:

see LICENSE file

Instance Method Summary (collapse)

Instance Method Details

- (Object) create



38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/admin/sponsors_controller.rb', line 38

def create
  @sponsor = Sponsor.new(params[:sponsor])
  if @sponsor.save
    @sponsor.tag_names=(params['sponsor']['tag_names'])
    flash[:notice] = 'Sponsor was successfully created and added to the bottom of the list. You can now arrange the display order if needed.'
    AdminLog.log_event(current_person, AdminLog::CREATE_SPONSOR,{:sponsor_id => @sponsor.id})
    redirect_to(admin_sponsors_url)
  else
    render(:action => 'new')
  end
end

- (Object) destroy



66
67
68
69
70
71
72
# File 'app/controllers/admin/sponsors_controller.rb', line 66

def destroy
  @sponsor = Sponsor.find_by_id(params[:id])
  AdminLog.log_event(current_person, AdminLog::DELETE_SPONSOR,{:sponsor_id => @sponsor.id})
  @sponsor.destroy
  flash[:notice] = 'Sponsor was successfully deleted.'
  redirect_to(admin_sponsors_url)
end

- (Object) edit



50
51
52
# File 'app/controllers/admin/sponsors_controller.rb', line 50

def edit
  @sponsor = Sponsor.find(params[:id])
end

- (Object) index



24
25
26
27
# File 'app/controllers/admin/sponsors_controller.rb', line 24

def index
  set_title('Manage Sponsors - Pubsite Admin')
  @sponsors = Sponsor.find(:all, :order => 'position')
end

- (Object) new



33
34
35
36
# File 'app/controllers/admin/sponsors_controller.rb', line 33

def new
  @sponsor = Sponsor.new
  @logos =  Logo.find(:all)
end

- (Object) show



29
30
31
# File 'app/controllers/admin/sponsors_controller.rb', line 29

def show
  @sponsor = Sponsor.find(params[:id])
end

- (Object) update



54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/admin/sponsors_controller.rb', line 54

def update
  @sponsor = Sponsor.find(params[:id])
  if @sponsor.update_attributes(params[:sponsor])
    @sponsor.tag_names=(params['sponsor']['tag_names'])
    AdminLog.log_event(current_person, AdminLog::UPDATE_SPONSOR,{:sponsor_id => @sponsor.id})
    flash[:notice] = 'Sponsor was successfully updated.'
    redirect_to(admin_sponsors_url)
  else
    render(:action => 'edit')
  end
end

- (Object) update_positions

ajax call to update the position of the ads relative to each other



15
16
17
18
19
20
21
22
# File 'app/controllers/admin/sponsors_controller.rb', line 15

def update_positions
  params[:sortable_list].each_with_index do |id, position|
    ad = Sponsor.find(id)
    ad.update_attribute(:position, (position + 1))
  end
  AdminLog.log_event(current_person, AdminLog::REORDER_SPONSORS,{:first => params[:sortable_list][0]})
  render :nothing => true
end