Class: RubyCms::Admin::ContentBlocksController

Inherits:
BaseController show all
Includes:
RubyCms::AdminPagination, RubyCms::AdminTurboTable
Defined in:
app/controllers/ruby_cms/admin/content_blocks_controller.rb

Constant Summary

Constants included from RubyCms::AdminPagination

RubyCms::AdminPagination::DEFAULT_MAX_PER_PAGE, RubyCms::AdminPagination::DEFAULT_MIN_PER_PAGE

Instance Method Summary collapse

Methods included from RubyCms::AdminTurboTable

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

Methods included from RubyCms::AdminPagination

#paginate_collection, #set_pagination_vars

Instance Method Details

#createObject



43
44
45
46
47
48
# File 'app/controllers/ruby_cms/admin/content_blocks_controller.rb', line 43

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



54
55
56
57
# File 'app/controllers/ruby_cms/admin/content_blocks_controller.rb', line 54

def destroy
  @content_block.destroy
  redirect_with_notice("deleted")
end

#editObject



38
39
40
41
# File 'app/controllers/ruby_cms/admin/content_blocks_controller.rb', line 38

def edit
  @blocks_by_locale = load_blocks_by_locale_for_edit
  render :show
end

#indexObject



15
16
17
18
19
20
21
22
23
# File 'app/controllers/ruby_cms/admin/content_blocks_controller.rb', line 15

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



30
31
32
33
34
35
36
# File 'app/controllers/ruby_cms/admin/content_blocks_controller.rb', line 30

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



25
26
27
28
# File 'app/controllers/ruby_cms/admin/content_blocks_controller.rb', line 25

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

#updateObject



50
51
52
# File 'app/controllers/ruby_cms/admin/content_blocks_controller.rb', line 50

def update
  unified_locale_params? ? update_all_locales : update_single_block
end