Class: IshLibManager::SitesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ish_lib_manager/sites_controller.rb

Constant Summary collapse

PERMITTED_ATTRIBUTES =
[ :domain, :lang, :title, :subhead, :homepage_layout, :layout,
  :n_features, :n_newsitems, :is_trash, :is_ads_enabled, :is_private,
  :home_redirect_path, :is_video_enabled, :is_resume_enabled, :is_primary
]

Instance Method Summary collapse

Methods inherited from ApplicationController

#set_lists

Instance Method Details

#createObject



42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/ish_lib_manager/sites_controller.rb', line 42

def create
  authorize! :create, Site.new
  @site = Site.new params[:site].permit( PERMITTED_ATTRIBUTES )
  if @site.save
    flash[:notice] = 'Success'
  else
    flash[:error] = 'No Luck. ' + @site.errors.inspect
  end
  redirect_to manager_sites_path
end

#editObject



32
33
34
35
# File 'app/controllers/ish_lib_manager/sites_controller.rb', line 32

def edit
  @site = Site.find params[:id]
  authorize! :edit, @site
end

#indexObject



9
10
11
12
# File 'app/controllers/ish_lib_manager/sites_controller.rb', line 9

def index
  authorize! :index, Site
  @sites = Site.all.order_by( :domainname => :desc, :lang => :desc )
end

#newObject



37
38
39
40
# File 'app/controllers/ish_lib_manager/sites_controller.rb', line 37

def new
  authorize! :new, Site.new
  @site = Site.new
end

#newsitem_deleteObject



65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/ish_lib_manager/sites_controller.rb', line 65

def newsitem_delete    
  @site = Site.find params[:site_id]
  authorize! :update, @site
  
  n = @site.newsitems.find( params[:newsitem_id] )
  n.delete
  @site.save
  flash[:notice] = 'Probably successfully deleted a newsitem.'
  redirect_to manager_site_path( @site.id )
end

#showObject



20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/ish_lib_manager/sites_controller.rb', line 20

def show
  @site = Site.find params[:id]
  authorize! :show, @site
  
  @galleries = @site.galleries.unscoped.where({ :is_trash => false }).page( params[:galleries_page] ).per( 10 )
  @reports = @site.reports.unscoped.where({ :is_trash => false }).page( params[:reports_page] ).per( 10 )
  @videos = @site.videos.page( params[:videos_page] ).per( 5 )
  @tags = @site.tags.page( params[:tags_page] ).per( 100 )
  @features = @site.features.page( params[:features_page] ).per( 9 )
  @newsitems = @site.newsitems.page( params[:newsitems_page] ).per( 10 )
end

#trashObject



14
15
16
17
18
# File 'app/controllers/ish_lib_manager/sites_controller.rb', line 14

def trash
  authorize! :trash, Site
  @sites = Site.unscoped.where( :is_trash => true ).order_by( :domainname => :desc, :lang => :desc )
  render :action => :index
end

#updateObject



53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/ish_lib_manager/sites_controller.rb', line 53

def update
  @site = Site.find params[:id]
  authorize! :update, @site
  
  if @site.update_attributes params[:site].permit( PERMITTED_ATTRIBUTES )
    flash[:notice] = 'Success'
  else
    flash[:error] = 'No Luck'
  end
  redirect_to sites_path
end