Class: Spina::Blocks::Admin::BlocksController
- Inherits:
-
Admin::AdminController
- Object
- Admin::AdminController
- Spina::Blocks::Admin::BlocksController
- Defined in:
- app/controllers/spina/blocks/admin/blocks_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #edit_content ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #sort ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/spina/blocks/admin/blocks_controller.rb', line 34 def create @block = Spina::Blocks::Block.new(block_params) if @block.save redirect_to spina.edit_blocks_admin_block_url(@block) else @block_templates = current_theme.try(:block_templates) || [] render turbo_stream: turbo_stream.update( helpers.dom_id(@block, :new_block_form), partial: 'new_block_form' ) end end |
#destroy ⇒ Object
81 82 83 84 85 |
# File 'app/controllers/spina/blocks/admin/blocks_controller.rb', line 81 def destroy flash[:info] = I18n.t('spina.blocks.deleted') @block.destroy redirect_to spina.blocks_admin_blocks_url end |
#edit ⇒ Object
47 48 49 50 |
# File 'app/controllers/spina/blocks/admin/blocks_controller.rb', line 47 def edit I18n.t('spina.blocks.title'), spina.blocks_admin_blocks_path, class: 'text-gray-400' @block.title end |
#edit_content ⇒ Object
52 53 54 55 56 |
# File 'app/controllers/spina/blocks/admin/blocks_controller.rb', line 52 def edit_content @parts = current_theme.block_templates&.find do |bt| bt[:name].to_s == @block.block_template.to_s end&.dig(:parts) || [] end |
#index ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/spina/blocks/admin/blocks_controller.rb', line 15 def index I18n.t('spina.blocks.title'), spina.blocks_admin_blocks_path @block_templates = current_theme.try(:block_templates) || [] if params[:block_template].present? @current_block_template = params[:block_template] @blocks = Spina::Blocks::Block.where(block_template: @current_block_template).sorted else @current_block_template = nil @blocks = Spina::Blocks::Block.sorted end end |
#new ⇒ Object
29 30 31 32 |
# File 'app/controllers/spina/blocks/admin/blocks_controller.rb', line 29 def new @block_templates = current_theme.try(:block_templates) || [] @block = Spina::Blocks::Block.new(block_template: params[:block_template]) end |
#sort ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'app/controllers/spina/blocks/admin/blocks_controller.rb', line 72 def sort params[:ids].each.with_index do |id, index| Spina::Blocks::Block.where(id: id).update_all(position: index + 1) end flash.now[:info] = I18n.t('spina.blocks.sorting_saved') render_flash end |
#update ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/spina/blocks/admin/blocks_controller.rb', line 58 def update Mobility.locale = @locale if @block.update(block_params) flash[:success] = I18n.t('spina.blocks.saved') redirect_to spina.edit_blocks_admin_block_url(@block, params: { locale: @locale }) else I18n.t('spina.blocks.title'), spina.blocks_admin_blocks_path, class: 'text-gray-400' Mobility.locale = I18n.locale @block.title flash.now[:error] = I18n.t('spina.blocks.couldnt_be_saved') render :edit, status: :unprocessable_entity end end |