In Rails models; for symbols get automatically converted to YAML when saving to DB. What is the corr

Posted by Ram on Stack Overflow See other posts from Stack Overflow or by Ram
Published on 2010-05-12T08:37:18Z Indexed on 2010/05/12 9:04 UTC
Read the original article Hit count: 131

In my model example Game, has a status column. But I usually set status by using symbols. Example

self.status = :active

    MATCH_STATUS = { 
      :betting_on => "Betting is on",
      :home_team_won => "Home team has won",
      :visiting_team_won => "Visiting team has one",
      :game_tie => "Game is tied"
    }.freeze

def viewable_status
  MATCH_STATUS[self.status]
end

I use the above Map to switch between viewable status and viceversa.

However when the data gets saved to db, ActiveRecord appends "--- " to each status. So when I retrieve back the status is screwed.

What should be the correct approach?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails