Class: Panda::CMS::Admin::BlockContentsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/panda/cms/admin/block_contents_controller.rb

Instance Method Summary collapse

Methods included from Panda::CMS::ApplicationHelper

#active_link?, #block_link_to, #component, #level_indent, #menu_indent, #nav_class, #nav_highlight_colour_classes, #panda_cms_editor, #panda_cms_form_with, #selected_nav_highlight_colour_classes, #table_indent, #title_tag

Instance Method Details

#updateObject

Returns:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/panda/cms/admin/block_contents_controller.rb', line 12

def update
  Rails.logger.debug "Content params: #{params.inspect}"
  Rails.logger.debug "Raw content: #{request.raw_post}"

  # Ensure content isn't HTML escaped before saving
  if params[:content].present?
    # Convert ActionController::Parameters to a string if needed
    content_str = params[:content].is_a?(ActionController::Parameters) ? params[:content].to_json : params[:content].to_s
    content = CGI.unescapeHTML(content_str)
  else
    content = nil
  end

  begin
    if content && @block_content.update!(content: content)
      @block_content.page.touch
      render json: @block_content, status: :ok
    else
      render json: @block_content.errors, status: :unprocessable_entity
    end
  rescue => e
    Rails.logger.error "Error updating block content: #{e.message}"
    render json: {error: e.message}, status: :unprocessable_entity
  end
end