Class: Comfy::Admin::Cms::PagesController
- Inherits:
-
BaseController
- Object
- BaseController
- Comfy::Admin::Cms::PagesController
- Defined in:
- app/controllers/comfy/admin/cms/pages_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #form_fragments ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #reorder ⇒ Object
- #toggle_branch ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'app/controllers/comfy/admin/cms/pages_controller.rb', line 31 def create @page.save! flash[:success] = I18n.t('comfy.admin.cms.pages.created') redirect_to action: :edit, id: @page rescue ActiveRecord::RecordInvalid flash.now[:danger] = I18n.t('comfy.admin.cms.pages.creation_failure') render action: :new end |
#destroy ⇒ Object
49 50 51 52 53 |
# File 'app/controllers/comfy/admin/cms/pages_controller.rb', line 49 def destroy @page.destroy flash[:success] = I18n.t('comfy.admin.cms.pages.deleted') redirect_to action: :index end |
#edit ⇒ Object
27 28 29 |
# File 'app/controllers/comfy/admin/cms/pages_controller.rb', line 27 def edit render end |
#form_fragments ⇒ Object
55 56 57 58 |
# File 'app/controllers/comfy/admin/cms/pages_controller.rb', line 55 def form_fragments @page = @site.pages.find_by(id: params[:id]) || @site.pages.new @page.layout = @site.layouts.find_by(id: params[:layout_id]) end |
#index ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/comfy/admin/cms/pages_controller.rb', line 9 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
23 24 25 |
# File 'app/controllers/comfy/admin/cms/pages_controller.rb', line 23 def new render end |
#reorder ⇒ Object
70 71 72 73 74 75 |
# File 'app/controllers/comfy/admin/cms/pages_controller.rb', line 70 def reorder (params[:comfy_cms_page] || []).each_with_index do |id, index| ::Comfy::Cms::Page.where(id: id).update_all(position: index) end head :ok end |
#toggle_branch ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/comfy/admin/cms/pages_controller.rb', line 60 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 # do nothing end |
#update ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/controllers/comfy/admin/cms/pages_controller.rb', line 40 def update @page.save! flash[:success] = I18n.t('comfy.admin.cms.pages.updated') redirect_to action: :edit, id: @page rescue ActiveRecord::RecordInvalid flash.now[:danger] = I18n.t('comfy.admin.cms.pages.update_failure') render action: :edit end |