I have this controller code:
...
field_array.each do |f|
f = f.to_sym
model.send("#{f}=", "#{parm_hash[f]}") if
model.attribute_present?(f)
end
return model
...
field_array is an array of attribute names as strings.
parm_hash is the params hash returned from the view associated with
model.
If the value associated with an attribute_key is anything but a date
then this works and the value is set. If the value is a date then it
sets nil instead.
I have this controller code:
...
field_array.each do |f|
f = f.to_sym
model.send("#{f}=", "#{parm_hash[f]}") if
model.attribute_present?(f)
end
return model
...
field_array is an array of attribute names as strings.
parm_hash is the params hash returned from the view associated with
model.
If the value associated with an attribute_key is anything but a date
then this works and the value is set. If the value is a date then it
sets nil instead.
because with a date you can't pull the value from the params hash in
one go like that - there is one value in the hash for each component
(day, month, year). There's more about this at
because with a date you can't pull the value from the params hash in
one go like that - there is one value in the hash for each component
(day, month, year). There's more about this at
Dates, params and you - Space Vatican
Fred
I looked at this reference, but it seems to relate specifically to the
Rails date chooser, which I am not using. I dumped the hash contents
passed to the code thus:
print parm_hash.to_yaml
field_array.each do |f|
f = f.to_sym
model.send("#{f}=", "#{parm_hash[f]}") if
model.attribute_present?(f)
end
return model
> because with a date you can't pull the value from the params hash in
> one go like that - there is one value in the hash for each component
> (day, month, year). There's more about this at
>Dates, params and you - Space Vatican
> Fred
I looked at this reference, but it seems to relate specifically to the
Rails date chooser, which I am not using.
Ahh. As you point out, attribute_present? does not refer to the
attribute itself, but to its current value. I should think that given
the PoLS this method would be better called attribute_set? but no
matter.
I suppose that I should use method_missing instead.