Sha256: 85c8fb4804190edb17ac0a0981e7eeae7378171eb4ccc6525daa85d09864d655

Contents?: true

Size: 1.67 KB

Versions: 21

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

require "base64"

class Admin::PagesController < Admin::BaseController
  before_action :set_macro, only: [:new, :edit]
  before_action :set_page, only: [:edit, :update, :destroy]

  def index
    @search = params[:search] || {}
    @pages = Page.search_with(@search).page(params[:page]).
      per(this_blog.admin_display_elements)
  end

  def new
    @page = Page.new
    @page.text_filter_name ||= default_text_filter
    @page.user_id = current_user.id
    @page.state = "published"
    render layout: "editor"
  end

  def edit
    @page.text_filter_name ||= default_text_filter
    render layout: "editor"
  end

  def create
    @page = Page.new(page_params)
    @page.published_at = Time.zone.now
    @page.blog = this_blog
    @page.user_id = current_user.id

    if @page.save
      redirect_to admin_pages_url, notice: I18n.t("admin.pages.new.success")
    else
      render :new, layout: "editor"
    end
  end

  def update
    @page.text_filter_name ||= default_text_filter
    if @page.update(page_params)
      redirect_to admin_pages_url, notice: I18n.t("admin.pages.edit.success")
    else
      render :edit
    end
  end

  def destroy
    destroy_a(Page)
  end

  private

  def default_text_filter
    current_user.text_filter_name || this_blog.text_filter
  end

  def set_macro
    @macros = TextFilterPlugin.macro_filters
  end

  # Use callbacks to share common setup or constraints between actions.
  def set_page
    @page = Page.find(params[:id])
  end

  # Never trust parameters from the scary internet, only allow the white list through.
  def page_params
    params.require(:page).permit(:title, :body, :name, :state, :text_filter_name)
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
HornsAndHooves-publify_core-10.5.0 app/controllers/admin/pages_controller.rb
HornsAndHooves-publify_core-10.4.0 app/controllers/admin/pages_controller.rb
HornsAndHooves-publify_core-10.3.0 app/controllers/admin/pages_controller.rb
HornsAndHooves-publify_core-10.2.0 app/controllers/admin/pages_controller.rb
publify_core-9.2.10 app/controllers/admin/pages_controller.rb
HornsAndHooves-publify_core-10.1.1 app/controllers/admin/pages_controller.rb
HornsAndHooves-publify_core-10.1.0 app/controllers/admin/pages_controller.rb
HornsAndHooves-publify_core-10.0.3 app/controllers/admin/pages_controller.rb
HornsAndHooves-publify_core-10.0.2 app/controllers/admin/pages_controller.rb
HornsAndHooves-publify_core-10.0.1 app/controllers/admin/pages_controller.rb
HornsAndHooves-publify_core-10.0.0 app/controllers/admin/pages_controller.rb
publify_core-9.2.9 app/controllers/admin/pages_controller.rb
publify_core-9.2.8 app/controllers/admin/pages_controller.rb
publify_core-9.2.7 app/controllers/admin/pages_controller.rb
publify_core-9.2.6 app/controllers/admin/pages_controller.rb
publify_core-9.2.5 app/controllers/admin/pages_controller.rb
publify_core-9.2.4 app/controllers/admin/pages_controller.rb
publify_core-9.2.3 app/controllers/admin/pages_controller.rb
publify_core-9.2.2 app/controllers/admin/pages_controller.rb
publify_core-9.2.1 app/controllers/admin/pages_controller.rb