Class: Admin::ContentBlocksController

Inherits:
ApplicationController
  • Object
show all
Includes:
AdminPagination, AdminTurboTable, AuditLoggable
Defined in:
lib/generators/ruby_cms/templates/controllers/admin/content_blocks_controller.rb

Constant Summary

Constants included from AdminPagination

AdminPagination::DEFAULT_MAX_PER_PAGE, AdminPagination::DEFAULT_MIN_PER_PAGE

Instance Method Summary collapse

Methods included from AdminTurboTable

#turbo_frame_id, #turbo_frame_request?, #turbo_redirect_to, #turbo_render_form, #turbo_render_index, #turbo_stream_replace_table, #turbo_stream_request?, #turbo_stream_update_table

Methods included from AdminPagination

#paginate_collection, #set_pagination_vars

Instance Method Details

#createObject



42
43
44
45
46
47
# File 'lib/generators/ruby_cms/templates/controllers/admin/content_blocks_controller.rb', line 42

def create
  @content_block = ::ContentBlock.new(content_block_params)
  @content_block.record_update_by(current_user_cms)
  @content_block.published = true if @content_block.published.nil?
  save_and_respond(@content_block, :new)
end

#destroyObject



53
54
55
56
57
58
# File 'lib/generators/ruby_cms/templates/controllers/admin/content_blocks_controller.rb', line 53

def destroy
  key = @content_block.key
  @content_block.destroy
  audit!(:content_block_deleted, target: "ContentBlock:#{key}", summary: "Deleted content block #{key}", meta: { key: })
  redirect_with_notice("deleted")
end

#editObject



37
38
39
40
# File 'lib/generators/ruby_cms/templates/controllers/admin/content_blocks_controller.rb', line 37

def edit
  @blocks_by_locale = load_blocks_by_locale_for_edit
  render :show
end

#indexObject



14
15
16
17
18
19
20
21
22
# File 'lib/generators/ruby_cms/templates/controllers/admin/content_blocks_controller.rb', line 14

def index
  collection = content_blocks_collection
  @content_blocks = html_index_blocks(collection)

  respond_to do |format|
    format.html { render_index_html }
    format.json { render json: json_index_blocks(collection) }
  end
end

#newObject



29
30
31
32
33
34
35
# File 'lib/generators/ruby_cms/templates/controllers/admin/content_blocks_controller.rb', line 29

def new
  @content_block = ::ContentBlock.new(new_block_params)
  # Most users expect newly created blocks to show on the site immediately.
  # The public helper renders only `published` blocks, while the visual editor
  # preview can show unpublished ones, which is confusing.
  @content_block.published = true if @content_block.published.nil?
end

#showObject



24
25
26
27
# File 'lib/generators/ruby_cms/templates/controllers/admin/content_blocks_controller.rb', line 24

def show
  @blocks_by_locale = load_blocks_by_locale_for_edit
  respond_with_block(@content_block)
end

#updateObject



49
50
51
# File 'lib/generators/ruby_cms/templates/controllers/admin/content_blocks_controller.rb', line 49

def update
  unified_locale_params? ? update_all_locales : update_single_block
end