Guest User

Untitled

a guest
Jul 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. @image = GalleryImage.new(image_params.except(:tags))
  2. @image.user = current_user
  3.  
  4. @queued = QueuedImage.new(user: current_user)
  5. @queued.image = @image
  6.  
  7. def image_to_json
  8. self.image_data = @image.to_json(include: :plain_images)
  9. end
  10.  
  11. def update
  12. @queued = QueuedImage.find(params[:id])
  13. hash_as_string = @queued.image_data
  14. i_data = JSON.parse(hash_as_string.gsub('=>', ':'))
  15. i_data["title"] = params["title"]
  16. i_data["description"] = params["description"]
  17. i_data["folder_id"] = params["folder_id"]
  18. i_data["nsfw"] = params["nsfw"]
  19. i_data["tags"] = params["tags"]
  20. @queued.image_data = i_data
  21.  
  22. if @queued.save
  23. render json: @queued, scope: current_user
  24. else
  25. render json: @queued.errors.as_json(full_messages: true), scope: current_user, status: :unprocessable_entity
  26. end
  27. end
Add Comment
Please, Sign In to add comment