Bug or Feature?

Hello,

I know this came up before hand, but I haven’t seen a conclusive
answer. This is with regards to the MultiparameterAssignmentErrors and
select_date when submitting an invalid date (September 31st for
example). It seems that when an invalid date is submitted, the date
value should be set to nil as opposed to throw an exception that seems
a bit hard to catch elegantly and then provide validation.

The exception is raised in ActiveRecord::Base line 2002 and seems that
throwing that exception there is the intended feature.

That bit of code could possibly be rewritten as (completely un tested):


def execute_callstack_for_multiparameter_attributes(callstack)
errors = []
callstack.each do |name, values|
klass = (self.class.reflect_on_aggregation(name.to_sym) ||
column_for_attribute(name)).klass
if values.empty?
send(name + “=”, nil)
else
begin
send(name + “=”, Time == klass ? klass.local(*values) :
klass.new(*values))
rescue => ex
send(name + “=”, nil)
end
end
end
unless errors.empty?
raise MultiparameterAssignmentErrors.new(errors),
“#{errors.size} error(s) on assignment of multiparameter attributes”
end
end

Or, any ideas of how to elegantly catch invalid dates or other
multiparamter attributes at the validation stages?

-carl

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs