Class: Virgo::Admin::PageModulesController

Inherits:
BaseController show all
Defined in:
app/controllers/virgo/admin/page_modules_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#authorize_admin_user, #search, #set_is_admin_view

Methods included from RenderHelper

#render_content, #with_format

Methods included from Virgo::ApplicationHelper

#action?, #admin?, #admin_access?, #admin_view?, #alerts, #base_errors, #category_timestamp, #column_timestamp, #compact_html, #controller?, #decode_html_entities, #expanded_post_url, #is_admin_view?, #page_url, #post_time_format, #post_timestamp, #production?, #redis_timestamp_key_for, #site, #site_key, #superuser?, #tabbed_param, #word_count

Instance Method Details

#editObject



8
9
10
11
12
# File 'app/controllers/virgo/admin/page_modules_controller.rb', line 8

def edit
  authorize! :manage, PageModule

  @page_modules = PageModule.visible_to_admins.order(weight: :asc)
end

#edit_subjectObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/virgo/admin/page_modules_controller.rb', line 14

def edit_subject
  if request.patch?
    if page_module_params.nil? || @page_module.update(page_module_params)
      @page_module.page_module_posts.map &:destroy
      if params[:post_ids].present?
        params[:post_ids].each_with_index do |post_id, index|
          @page_module.page_module_posts.create!(post_id: post_id, position: index)
        end
      end
      flash[:notice] = "Settings updated successfully"
      redirect_to admin_edit_page_module_subject_path(@page_module) and return
    end
  end
end

#updateObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/virgo/admin/page_modules_controller.rb', line 29

def update
  authorize! :manage, PageModule

  params[:page_modules].each_pair do |id, enabled_val|
    page_module = PageModule.find(id)

    page_module.update!(enabled: enabled_val)
  end

  flash[:notice] = "Page module settings updated"

  redirect_to admin_page_modules_edit_path
end