[Nitro] Building objects from Strings
surrender_it at yahoo.it
Wed Aug 9 06:00:49 EDT 2006
Michael Fellinger ha scritto:
> On Wednesday 09 August 2006 17:41, gabriele renzi wrote:
>>I have a somewhat working interface to change Settings from the
>>administration UI, and I think it is a Good Thing(TM).
>>But bat the moment it is slightly fragile, and uses a hacky way of
>>getting the values from the user.
>>Basically, I'm providigin small text fields for each "good" setting, and
>>in the server side I'm assigning to the setting the value by
>>transforming it in the right type.
>> setting.value = setting.type.new(param[name])
>>Now to the bad one: ruby does not have String constructors for many
>>things, so the above is working fine for String and Numerics.
>>I added the handling for Booleans as a simple
>>def TrueClass.new(arg) arg=='true' end
>>def FalseClass.new(arg) not TrueClass.new(arg) end
>>A better solution could be using YAML.load on the given String.
>>Someone has other ideas or could point me to something in facets (i.e.
> did you think about checkboxes?
I did think of using Nitro's Controls for existing types, but in the
original basic implementation I was just doing an eval() on the string,
and nitro's checkbox control returns "t" or "f" instead of "true" and
"false" so this would have not worked.
If I was allowed to change that we could make this a setting, i.e.
AdminPart.setting_input = (:controls or :text)
Or I could change the implementation of TrueClass.new, but that would
mean keeping this code around, which I'd like to remove alltogether.
blog en: http://www.riffraff.info
blog it: http://riffraff.blogsome.com
jabber : rff.rff at gmail dot com
More information about the Nitro-general