How to store and compare :symbols in an ActiveRecord (Ruby on Rails)

后端 未结 7 1372
梦谈多话
梦谈多话 2021-02-05 04:51

I thought it would be good to populate a status field in an activeRecord table using constants. However, when it comes to checking if this status has a particular status, I\'m h

7条回答
  •  余生分开走
    2021-02-05 05:02

    At the request of ecoologic, here is my comment as an answer:

    ecoologic has a good solution for you, but I would recommend steering away from this and making a class with constants in it. That you can do things like e.status = Statuses::CANCELLED. And internally that could be a string and it doesn't matter. You're still using constants, and it will error out if that constant doesn't exist, and it's cleaner that way.

提交回复
热议问题