Class: Admin::AdsController
- Inherits:
-
AdminController
- Object
- AdminController
- Admin::AdsController
- Defined in:
- app/controllers/admin/ads_controller.rb
Instance Method Summary collapse
- #activate ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#activate ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/controllers/admin/ads_controller.rb', line 4 def activate @ad = Ad.find_sys_id(_sid, params[:id]) if params[:mode]=='approve' @ad.update_attributes(:approved_by_id=>current_user.id) notice = "Ad is now approved" elsif params[:mode]=='activate' @ad.update_attributes(:activated=>Time.now) notice = "Ad is not activated" else @ad.update_attributes(:activated=>nil) notice = "Ad is now deactivated" end redirect_to request.referer, :notice=>notice end |
#create ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/admin/ads_controller.rb', line 36 def create @ad = Ad.new(params[:ad]) @ad.system_id = _sid @ad.activated = Time.now # @ad.duration = params[:ad][:duration].to_i @ad.approved_by_id = current_user.id @ad.user_id = current_user.id @ad.name = params[:ad][:name] @ad.start_date = params[:ad][:start_date] @ad.end_date = params[:ad][:end_date] #@ad.start_date + @ad.duration.send(zone.period.downcase) rescue nil zones = check_zones if zones.instance_of?(String) render :action=>'new', :notice=>zones return end if @ad.save && params[:ad_zones].length>0 zones.each { |zone| @ad.ad_zones << zone } @ad.height = @ad.ad_zones.first.ad_unit.height @ad.width = @ad.ad_zones.first.ad_unit.width redirect_to [:admin, @ad], :notice => "Successfully created ad." else render :action => 'new' end end |
#destroy ⇒ Object
86 87 88 89 90 |
# File 'app/controllers/admin/ads_controller.rb', line 86 def destroy @ad = Ad.find_sys_id(_sid,params[:id]) @ad.destroy redirect_to admin_ads_url, :notice => "Successfully destroyed ad." end |
#edit ⇒ Object
63 64 65 |
# File 'app/controllers/admin/ads_controller.rb', line 63 def edit @ad = Ad.find_sys_id(_sid, params[:id]) end |
#index ⇒ Object
20 21 22 23 24 25 |
# File 'app/controllers/admin/ads_controller.rb', line 20 def index @ads = Ad.sys(_sid).includes({:ad_zones=>:ad_unit}).order("ads.updated_at desc") @ads = @ads.joins(:ad_zones).where("ad_zones.id = #{params[:zone_id]}") if params[:zone_id] @ads = @ads.where(:user_id=>params[:user_id]) if params[:user_id] @ads = @ads.page(params[:page]).per(25) end |
#new ⇒ Object
31 32 33 34 |
# File 'app/controllers/admin/ads_controller.rb', line 31 def new @ad = Ad.new @ad.weighting = 5 end |
#show ⇒ Object
27 28 29 |
# File 'app/controllers/admin/ads_controller.rb', line 27 def show @ad = Ad.find_sys_id(_sid, params[:id]) end |
#update ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/admin/ads_controller.rb', line 67 def update @ad = Ad.find_sys_id(_sid, params[:id]) zones = check_zones if zones.instance_of?(String) @ad.errors.add(:ad_zones, zones) render :action=>'edit' return end if @ad.update_attributes(params[:ad]) && params[:ad_zones].length>0 @ad.ad_zones.delete_all zones.each { |zone| @ad.ad_zones << zone } redirect_to [:admin, @ad], :notice => "Successfully updated ad." else render :action => 'edit' end end |