-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add basic support for xml #1133
Conversation
Looks fine, missing as_xml and delegation to adapter in serializable resource, but i hope we're not promissong too mich by adding it... All rails models already support xml... I have some thougts on design for supporting sifferent mime types Who wants to maintain it in ams? |
Also, AMS has json code all over.. |
@bf4 Does it? I don't see much code in AMS that is really json specific. |
def test_render_object_xml | ||
get :render_object_xml | ||
|
||
hash = Hash.from_xml(@response.body).each_value.first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, ActiveModel::Serializers::XML does this.. https://github.com/rails/rails/blob/4-2-stable/activemodel/lib/active_model/serializers/xml.rb#L232-L234
@beauby What do you think of, instead of adding this code to AMS, writing it up in docs, maybe still test it? e.g. # docs/other_mime_type.md
See the Rails built-in xml Renderer and how to override it
- https://github.com/rails/rails/blob/4-2-stable/actionpack/lib/action_controller/metal/renderers.rb#L66-L128
Or
Just override the xml renderer method Rails defines
# docs/xml_mime_example.rb
# In your ApplicationController or a mixin,
# Rails 4.0 - 4.1, use `:_render_option_xml`
# Rails 4.2 use `:_render_with_renderer_xml`
# Rails 5 TBD
def _render_with_renderer_xml(xml, options)
options[:adapter] ||= :flatten_json # or :attributes, hopefully
serializable_resource = get_serializer(xml, options)
if serializable_resource == xml
super
else
super(serializable_resource, options).serializable_hash(options).to_xml
end
end |
@bf4 I do not have any strong feeling either way, to be honest. I made the PR because it seemed like a "quick win" for the project, but I personally have no use for it, so I'm fine if we decide to make it a note instead! |
Can we close this? |
I think so |
Unless we actually want to support xml. IMO, it needs to die. (Xml) |
I was keeping this issue open until we make a line in the docs about it. Le vendredi 2 octobre 2015, L. Preston Sego III [email protected]
Lucas Hosseini |
It's all in the title: do
render xml: resource
instead ofrender json: resource
, and you get xml (the actual format will depend on the adapter used).