Sha256: 55ce0df8384e433aba6cfacd2f822e914306d4c12f4287da48c818320dd6df23

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module PandaCms
  module Admin
    class BlockContentsController < ApplicationController
      before_action :set_page, only: %i[update]
      before_action :set_block_content, only: %i[update]
      before_action :set_paper_trail_whodunnit, only: %i[update]
      before_action :authenticate_admin_user!

      # @type PATCH/PUT
      # @return
      def update
        if @block_content.update!(content: params[:content])
          @block_content.page.touch # Update the page's updated_at
          render json: @block_content, status: :ok
        else
          render json: @block_content.errors, status: :unprocessable_entity
        end
      end

      private

      # @type private
      # @return PandaCms::Page
      def set_page
        @page = PandaCms::Page.find(params[:page_id])
      end

      # @type private
      # @return PandaCms::BlockContent
      def set_block_content
        @block_content = PandaCms::BlockContent.find(params[:id])
      end

      # Only allow a list of trusted parameters through.
      # @type private
      # @return ActionController::StrongParameters
      def block_content_params
        params.require(:block_content).permit(:content)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
panda_cms-0.6.3 app/controllers/panda_cms/admin/block_contents_controller.rb
panda_cms-0.6.2 app/controllers/panda_cms/admin/block_contents_controller.rb
panda_cms-0.6.1 app/controllers/panda_cms/admin/block_contents_controller.rb