Class: Occams::Admin::Cms::PagesController
- Inherits:
-
BaseController
- Object
- BaseController
- Occams::Admin::Cms::PagesController
- Includes:
- ReorderAction
- Defined in:
- app/controllers/occams/admin/cms/pages_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #form_fragments ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #toggle_branch ⇒ Object
- #update ⇒ Object
- #update_family ⇒ Object
Methods included from ReorderAction
Instance Method Details
#create ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/occams/admin/cms/pages_controller.rb', line 43 def create @page.save! update_family flash[:success] = I18n.t('occams.admin.cms.pages.created') redirect_to action: :edit, id: @page rescue ActiveRecord::RecordInvalid flash.now[:danger] = I18n.t('occams.admin.cms.pages.creation_failure') render action: :new end |
#destroy ⇒ Object
63 64 65 66 67 68 |
# File 'app/controllers/occams/admin/cms/pages_controller.rb', line 63 def destroy @page.destroy update_family flash[:success] = I18n.t('occams.admin.cms.pages.deleted') redirect_to action: :index end |
#edit ⇒ Object
34 35 36 |
# File 'app/controllers/occams/admin/cms/pages_controller.rb', line 34 def edit render end |
#form_fragments ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'app/controllers/occams/admin/cms/pages_controller.rb', line 70 def form_fragments @page = @site.pages.find_by(id: params[:id]) || @site.pages.new @page.layout = @site.layouts.find_by(id: params[:layout_id]) render( partial: 'occams/admin/cms/fragments/form_fragments', locals: { record: @page, scope: :page }, layout: false ) end |
#index ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/occams/admin/cms/pages_controller.rb', line 15 def index return redirect_to action: :new if site_has_no_pages? return index_for_redactor if params[:source] == 'redactor' @pages_by_parent = pages_grouped_by_parent @pages = if params[:categories].present? @site.pages.includes(:categories).for_category(params[:categories]).order(:label) else [@site.pages.root].compact end end |
#new ⇒ Object
30 31 32 |
# File 'app/controllers/occams/admin/cms/pages_controller.rb', line 30 def new render end |
#toggle_branch ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/occams/admin/cms/pages_controller.rb', line 81 def toggle_branch @pages_by_parent = pages_grouped_by_parent @page = @site.pages.find(params[:id]) s = (session[:cms_page_tree] ||= []) id = @page.id.to_s s.member?(id) ? s.delete(id) : s << id rescue ActiveRecord::RecordNotFound render nothing: true end |
#update ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/occams/admin/cms/pages_controller.rb', line 53 def update @page.save! update_family flash[:success] = I18n.t('occams.admin.cms.pages.updated') redirect_to action: :edit, id: @page rescue ActiveRecord::RecordInvalid flash.now[:danger] = I18n.t('occams.admin.cms.pages.update_failure') render action: :edit end |
#update_family ⇒ Object
38 39 40 41 |
# File 'app/controllers/occams/admin/cms/pages_controller.rb', line 38 def update_family @page.siblings.each(&:save!) if @page.siblings @page.parent.save! if @page.parent end |