Skip to content
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

rabl-rails renders JSON instead of XML in some cases #67

Closed
monfresh opened this issue Dec 1, 2014 · 3 comments
Closed

rabl-rails renders JSON instead of XML in some cases #67

monfresh opened this issue Dec 1, 2014 · 3 comments

Comments

@monfresh
Copy link

monfresh commented Dec 1, 2014

Hi, I came across rabl-rails and wanted to use it because of the performance gains, but unfortunately, for some reason, it's not working in my Rails 4.1.8 app with Ruby 2.1.3, whereas the original rabl gem works. The only difference is the gems (and using collection @locations versus collection :@locations). When I used rabl-rails, the controller was rendering JSON instead of XML. Then when I replaced rabl-rails with rabl, everything was working fine.

I have no idea where to start looking to troubleshoot why rabl-rails doesn't work, but here is the source code:
https://github.com/smcgov/ohana-api-smc

Here is the rabl template:
https://github.com/smcgov/ohana-api-smc/blob/master/app/views/api/v1/locations/index.xml.rabl

Here is the controller:
https://github.com/smcgov/ohana-api-smc/blob/master/app/controllers/api/v1/locations_controller.rb

Note that this template now has rabl-specific stuff in it, but you can still reproduce the issue with just a basic template that only defines attributes.

@ccocchi
Copy link
Owner

ccocchi commented Dec 2, 2014

In your example app, the view params does not contain a :format key so rabl-rails falls back to the default JSON renderer. To avoid that, if no params are found, now we use the request format (similarly of what rabl gem is doing).

I fix this in d9514b9, let me know if that works, i'll release a new version if so.

@monfresh
Copy link
Author

monfresh commented Dec 2, 2014

Thanks! I'll try it and let you know.

Since the rabl-rails gem is specific to Rails, I would have assumed that the format would be automatically picked up from the controller, as specified here. I've also specified the format in the rabl template name: index.xml.rabl.

Your README does not mention anything about specifying a format in the view params. Perhaps are you referring to this Content-Type issue? If so, that's because rabl support multiple frameworks, not just Rails. But since rabl-rails is specific to Rails, it should be able to automatically detect the proper format from the controller, no?

@ccocchi
Copy link
Owner

ccocchi commented Dec 30, 2014

This have been fixed in v0.4.1

@ccocchi ccocchi closed this as completed Dec 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants