Class: Admin::BannersController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/admin/banners_controller.rb

Instance Method Summary collapse

Instance Method Details



14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/admin/banners_controller.rb', line 14

def check_cookie
  unless params[:sort]
    params[:sort] = cookies['banner_sort'] ? cookies['banner_sort'] : 'name'
  end
  %w(active inactive).each do |view|
    if cookies['banner_view'] == view && params[:view] != view
      flash.keep
      redirect_to :view => view and return
    end
  end
end

#deactivate ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/admin/banners_controller.rb', line 26

def deactivate
  @banner = Banner.find(params[:id])
  case true
    when request.post? && @banner.unprotected?
      @banner.remove_all_placements!
      redirect_to admin_banners_url
    when @banner.protected?
      flash[:error] = @banner.cannot_be_deactivated_msg
      redirect_to admin_banners_url
    else
      response_for :deactivate
  end
end

#destroy ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/admin/banners_controller.rb', line 50

def destroy
  @banner = Banner.find(params[:id])
  if @banner.unprotected?
    super
    clear_model_cache
  else
    flash[:error] = @banner.cannot_be_removed_msg
    redirect_to admin_banners_url
  end
end

#remove ⇒ Object



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

def remove
  @banner = Banner.find(params[:id])
  if @banner.unprotected?
    response_for :remove
  else
    flash[:error] = @banner.cannot_be_removed_msg
    redirect_to admin_banners_url
  end
end