character_controller.rb 470 B

123456789101112131415161718192021
  1. class CharacterController
  2. def self.edit_character(params)
  3. char_hash = Character.from_form(params)
  4. if character = Character.find_by(edit_url: char_hash["edit_url"])
  5. character.update!(char_hash)
  6. character.reload
  7. else
  8. character = Character.create(char_hash)
  9. end
  10. character
  11. end
  12. def self.type_color(char)
  13. char_type = char.types.split("/").first || "Unknown"
  14. type = Type.find_by(name: char_type)
  15. type.color
  16. end
  17. end