image_controller.rb 844 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. class ImageController
  2. def self.default_image(content, char_id)
  3. img_url =
  4. /\*\*URL to the Character\'s Appearance\*\*\:\s(.*)/.match(content)
  5. img = CharImage.where(char_id: char_id),find_by(keyword: 'Default')
  6. case
  7. when img_url && img
  8. img.update(url: img_url[1])
  9. img.reload
  10. when img_url && !img
  11. img = CharImage.create(
  12. char_id: char_id,
  13. url: img_url[1],
  14. category: 'SFW',
  15. keyword: 'Default'
  16. )
  17. end
  18. img
  19. end
  20. def self.edit_image(params)
  21. img_hash = CharImage.from_form(params)
  22. char_id = img_hash["char_id"]
  23. keyword = img_hash["keyword"]
  24. img = CharImage.where(char_id: char_id).find_by(keyword: keyword)
  25. if img
  26. img.update!(img_hash)
  27. img.reload
  28. else
  29. img = CharImage.create(img_hash)
  30. end
  31. img
  32. end
  33. end