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

后端 未结 7 1455
梦谈多话
梦谈多话 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:19

    From Programming Ruby 1.9, regarding the == operator in the Symbol class (p. 729):

    Returns true only if sym and obj are symbols with the same object_id.
    

    Whatever you have stored in the DB will always have different object_id than the fixed object_id of the symbol (a pointer to a string literal, in this case).

提交回复
热议问题