|
Re: Bug or Feature?: msg#00256lang.ruby.rails.core
I agree that MultiParameterAttributes handling should be refactored, but since it probably won't be, here are a few alternatives. You can catch the error like shown here: http://i.nfectio.us/articles/2006/02/22/handling-invalid-dates-with-activerecord-date-helpers Or you can just bypass Rails dates and handle freeform input using the Chronic library like shown here: http://i.nfectio.us/articles/2006/09/07/validate-dates-in-your-models My suggestion is to not use the Rails Date Helpers. Bob Silva carl.lerche@xxxxxxxxx wrote: > 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 > ------------------- > > So, I'm not sure exactly what would be a good way to move this to > validations? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@xxxxxxxxxxxxxxxx To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@xxxxxxxxxxxxxxxx For more options, visit this group at http://groups.google.com/group/rubyonrails-core -~----------~----~----~----~------~----~------~--~---
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Bug or Feature?, carl.lerche@xxxxxxxxx |
|---|---|
| Next by Date: | Rails AR/Oracle Unit Test: [5209] failed (getting worse), Michael Schoen |
| Previous by Thread: | Bug or Feature?, carl.lerche@xxxxxxxxx |
| Next by Thread: | Rails AR/Oracle Unit Test: [5209] failed (getting worse), Michael Schoen |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |