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 -- Posted via http://www.ruby-forum.com/.
I wanted to write : in the controller using vehicle.status = eval(":#{vehicle.status}") didn''t helped The code above is not real, forgive the typos -- Posted via http://www.ruby-forum.com/.
Jean-Etienne Durand
2006-Aug-10 05:55 UTC
[Rails] Re: How to serialize a symbol coming from a Form
nuno wrote:> I wanted to write : > in the controller using > vehicle.status = eval(":#{vehicle.status}") > > didn''t helped > > The code above is not real, forgive the typosHi Nuno, Here is the syntax: "foo".to_sym Jean-Etienne -- Posted via http://www.ruby-forum.com/.