-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collections are not wrapped with with the right root tag in XML #59
Comments
I have a patch that can work around this issue... Haven't tested with parsing though. module Roar::Rails::ControllerAdditions
def prepare_model_for(format, model, options)
representer = representer_for(format, model, options)
if representer.representable_attrs.wrap == true
representer.representation_wrap = model.table_name.to_sym if format == :xml and detect_collection(model)
end
representer.prepare(model)
end
def detect_collection(model)
return true if model.kind_of?(Array)
return true if Object.const_defined?("ActiveRecord") and model.kind_of?(ActiveRecord::Relation)
end
end Need to restrict to relations only or things don't work right (no table_name) |
The above patch does not fix wrapping when the ":as =>" directive is used on a collection. The collection will use the self.class.name which is the original collection name, not the :as alias. Still looking for a fix for that. |
A test case/concrete example would be great. Thanks! |
Sure, I'll try to get you something soon. |
When serializing using XML, the root tag is incorrect. It is either or depending on the version of rails. I believe this ultimately tracks back to here: https://github.com/apotonick/representable/blob/master/lib/representable.rb#L58
The
self.class.name
does not properly track back to the model when it is a collection. A work-around for now is to placeself.representation_wrap = :collection_name
in the collection representer. Maybe this can be set by roar-rails, since I don't think representable is the right place to fix it.The text was updated successfully, but these errors were encountered: