PageRenderTime 1493ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/app/controllers/admin/images_controller.rb

https://gitlab.com/slice-group/speakers-web
Ruby | 91 lines | 66 code | 15 blank | 10 comment | 5 complexity | 3771ee53e97fd0343006716d2daaf361 MD5 | raw file
  1. module Admin
  2. # ImagesController
  3. class ImagesController < AdminController
  4. before_action :set_image, only: [:show, :edit, :update, :destroy]
  5. before_action :show_history, only: [:index]
  6. # GET /images
  7. def index
  8. @q = Image.ransack(params[:q])
  9. images = @q.result(distinct: true)
  10. @objects = images.page(@current_page)
  11. @total = images.size
  12. if !@objects.first_page? && @objects.size.zero?
  13. redirect_to images_path(page: @current_page.to_i.pred, search: @query)
  14. end
  15. end
  16. # GET /images/1
  17. def show
  18. end
  19. # GET /images/new
  20. def new
  21. @image = Image.new
  22. end
  23. # GET /images/1/edit
  24. def edit
  25. end
  26. # POST /images
  27. def create
  28. @image = Image.new(image_params)
  29. if @image.save
  30. redirect(@image, params)
  31. else
  32. render :new
  33. end
  34. end
  35. # PATCH/PUT /images/1
  36. def update
  37. if @image.update(image_params)
  38. redirect(@image, params)
  39. else
  40. render :edit
  41. end
  42. end
  43. def clone
  44. @image = Image.clone_record params[:image_id]
  45. if @image.save
  46. redirect_to admin_images_path
  47. else
  48. render :new
  49. end
  50. end
  51. # DELETE /images/1
  52. def destroy
  53. @image.destroy
  54. redirect_to admin_images_path, notice: actions_messages(@image)
  55. end
  56. def destroy_multiple
  57. Image.destroy redefine_ids(params[:multiple_ids])
  58. redirect_to(
  59. admin_images_path(page: @current_page, search: @query),
  60. notice: actions_messages(Image.new)
  61. )
  62. end
  63. private
  64. # Use callbacks to share common setup or constraints between actions.
  65. def set_image
  66. @image = Image.find(params[:id])
  67. end
  68. # Only allow a trusted parameter "white list" through.
  69. def image_params
  70. params.require(:image).permit(:image, :public, :title)
  71. end
  72. def show_history
  73. get_history(Image)
  74. end
  75. end
  76. end