Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def create
- add_more_images(images_params[:images])
- flash[:error] = "Failed uploading images" unless @item.save
- redirect_to admin_items_path
- end
- def destroy
- remove_image_at_index(params[:id].to_i)
- flash[:error] = "Failed deleting image" unless @item.save
- redirect_to admin_items_path
- end
- def add_more_images(new_images)
- images = @item.images
- images += new_images
- @item.images = images
- end
- def remove_image_at_index(index)
- remain_images = @item.images # copy the array
- deleted_image = remain_images.delete_at(index) # delete the target image
- deleted_image.try(:remove!) # delete image from S3
- @item.images = remain_images # re-assign back
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement