Hi,
I have a 'day' column in one of my models. This is stored in the DB as
an integer value 1..7. I want this field to appear as a string whenever
it appears in a view
e.g. if the DB has stored 1 I want the view to display 'Monday'
2 => Tuesday etc. etc.
How is this done in Rails? The value in the DB needs to be originally
set by the user using a drop down list with the options Monday..Sunday.
Basically, the user always needs to interact with a day string, but I
always want to store the corresponding integer in the DB.
Thanks in advance
You can create a DAYS_OF_THE_WEEK constant in config/environment.rb and reference this in your application. To get the relevant day of the week just do DAYS_OF_THE_WEEK[variable].