image_controller.rb 717 B

12345678910111213141516171819202122232425262728
  1. class ImageController
  2. def self.default_image(content, char_id)
  3. if image_url = /\*\*URL to the Character\'s Appearance\*\*\:\s(.*)/.match(content)
  4. unless CharImage.where(char_id: char_id).find_by(url: image_url[1])
  5. image = CharImage.create(char_id: char_id, url: image_url[1], category: 'SFW', keyword: 'Primary')
  6. end
  7. end
  8. if image
  9. image.url
  10. else
  11. image_url[1]
  12. end
  13. end
  14. def self.edit_image(params)
  15. img_hash = CharImage.from_form(params)
  16. if image = CharImage.where(char_id: img_hash["char_id"]).find_by(url: img_hash["url"])
  17. image.update!(img_hash)
  18. image.reload
  19. else
  20. image = CharImage.create(img_hash)
  21. end
  22. image
  23. end
  24. end