Class: Helios::Press::Admin::BlockImagesController
- Inherits:
-
BaseController
- Object
- ApplicationController
- BaseController
- Helios::Press::Admin::BlockImagesController
- Defined in:
- app/controllers/helios/press/admin/block_images_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/helios/press/admin/block_images_controller.rb', line 9 def create position = @block.block_images.maximum(:position).to_i + 1 @block_image = @block.block_images.build(block_image_params) @block_image.position = position if @block_image.save respond_to do |format| format.turbo_stream do render turbo_stream: turbo_stream.replace( "block-#{@block.id}", partial: "helios/press/admin/blocks/block", locals: { block: @block.reload, post: @post } ) end end else head :unprocessable_entity end end |
#destroy ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'app/controllers/helios/press/admin/block_images_controller.rb', line 37 def destroy position = @block_image.position @block_image.destroy @block.block_images.where("position > ?", position).update_all("position = position - 1") head :ok end |
#reorder ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'app/controllers/helios/press/admin/block_images_controller.rb', line 46 def reorder image_ids = params[:image_ids] image_ids.each_with_index do |image_id, index| @block.block_images.find(image_id).update_column(:position, index) end head :ok end |
#update ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/controllers/helios/press/admin/block_images_controller.rb', line 29 def update if @block_image.update(block_image_params) head :ok else head :unprocessable_entity end end |