Class: Admin::BannersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::BannersController
- Includes:
- RespondsToParent
- Defined in:
- app/controllers/admin/banners_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/admin/banners_controller.rb', line 15 def create @banner = @banner_set..build @banner.attributes = = SpudBanner.select('sort_order').where(:spud_banner_set_id => @banner_set.id).order('sort_order desc').first if @banner.sort_order = .sort_order + 1 end if request.xhr? if @banner.save flash.now[:notice] = 'SpudBanner created successfully' render 'show' else render 'new', :status => 422 end else @banner.save respond_to_parent do render 'legacy', :formats => [:js] end end end |
#destroy ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/admin/banners_controller.rb', line 59 def destroy if @banner.destroy flash.now[:notice] = 'SpudBanner deleted successfully' status = 200 else status = 422 end render :nothing => true, :status => status end |
#edit ⇒ Object
39 40 41 |
# File 'app/controllers/admin/banners_controller.rb', line 39 def edit respond_with @banner end |
#new ⇒ Object
10 11 12 13 |
# File 'app/controllers/admin/banners_controller.rb', line 10 def new @banner = @banner_set..new(:start_date => Date.today) respond_with @banner end |
#sort ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/admin/banners_controller.rb', line 69 def sort = params[:spud_banner_ids] = SpudBanner.where(:id => ).to_a SpudBanner.transaction do .each_with_index do |id, index| = .select{ |b| b.id == id.to_i }.first .update_column(:sort_order, index) end .last.owner.touch() end render :nothing => true, :status => 200 end |
#update ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/admin/banners_controller.rb', line 43 def update if request.xhr? if @banner.update_attributes() flash.now[:notice] = 'SpudBanner created successfully' render 'show' else render 'edit', :status => 422 end else @banner.update_attributes() respond_to_parent do render 'legacy', :formats => [:js] end end end |