Class: ActionTextSyntaxHighlighter::HighlightedCodeBlocksController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/action_text_syntax_highlighter/highlighted_code_blocks_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/action_text_syntax_highlighter/highlighted_code_blocks_controller.rb', line 5

def create
  @code_block = HighlightedCodeBlock.create
  render json: {
    sgid: @code_block.attachable_sgid,
    contentType: "text/html",
    content: render_to_string(
      partial: @code_block.to_trix_content_attachment_partial_path,
      locals: { highlighted_code_block: @code_block },
      formats: [:html]
    )
  }, status: :created
end

#updateObject



18
19
20
21
22
23
24
# File 'app/controllers/action_text_syntax_highlighter/highlighted_code_blocks_controller.rb', line 18

def update
  @code_block = ActionText::Attachable.from_attachable_sgid params[:id]
  @code_block.update(code_block_params)
  head :no_content
rescue ActiveRecord::RecordNotFound
  head :not_found
end