Hello, I would like to use serialized symbols as values for select in
forms.
eg.
class Vehicle < ActiveRecord::Base
@@statuses = {:wait => ‘No yet’, :ok => ‘Run run run’}
validates_inclusion_of status, :in => @@statutes.keys
Serialize status, Symbol
def self.statuses
@@statuses
end
end
Then, I can use Vehicle.statuses.invert to populate my select drop down
list in the form.
Unfortunately when the form is submited the ‘values’ sent are not
recognized as a symbols and an error occurs
“status was supposed to be a Symbol, but was a String”
I understand that the value posted is “wait” or “ok” and not :wait or
:ok but I didn’t found a way to convert them to symbols correctly.
in the controller using
vehicle.status = eval(":#{vehicle.status}")
Of course I might use strings as keys instead of symbols for the hashes
but I find them less readable in the source code.
Any help appreciated, thanks