image_controller.rb 775 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. if image = CharImage.where(char_id: char_id).find_by(keyword: 'Default')
  5. image.update(url: image_url[1])
  6. image.reload
  7. else
  8. image = CharImage.create(char_id: char_id, url: image_url[1], category: 'SFW', keyword: 'Default')
  9. end
  10. end
  11. image ? image.url : image_url[1]
  12. end
  13. def self.edit_image(params)
  14. img_hash = CharImage.from_form(params)
  15. if image = CharImage.where(char_id: img_hash["char_id"]).find_by(keyword: img_hash["keyword"])
  16. image.update!(img_hash)
  17. image.reload
  18. else
  19. image = CharImage.create(img_hash)
  20. end
  21. image
  22. end
  23. end