I’m curious how others would deal with this situation.
In my case, I have:
And accept XML requests in the following manner:Good Shipment Failure US Unknown FR
Now, my controller would look something like this ugly beast:
if package = params[:package]
package = Package.find_or_initialize_by_name(package)
if deliveries = package.delete(:deliveries)
deliveries.each do |d|
region = d.delete(:region)
region = Region.find_or_create_by_name(region[:name])
break if region.nil?
package.deliveries[-1].region = region
#save and more…
As one can see, this is horrible for several reasons. One of the big
ones being request validation and error handling.
Overriding package.from_xml is an option, but I find myself thinking
that I should be validating against request.body with say a DTD, as
opposed to picking apart the params hash. (Though I’ll have to pick it
apart anyways to create the models…)
Then I find my self thinking that creating a course grained validation
method like a DTD is stupid since I have my fine grain validation
logic within the given models.
Yes, I’ve heard of ROXML.