Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Forcing a specific :format using Rabl::Renderer.json w/ :scope option set. #315
I was wondering if there was a way to force the underlying renderer to use a specific format when using
My views are currently named like so
My views also make use of a helper method defined in the application controller called
With this example I get the following exception...
You'll notice this part
Looking at the Engine class it appears to set the format here: https://github.com/nesquena/rabl/blob/master/lib/rabl/engine.rb#L28 ...which calls this method here: https://github.com/nesquena/rabl/blob/master/lib/rabl/engine.rb#L211 seemingly checking the scope i passed in.
The problem is that I need the
The only solution I've found seems very ugly and wrong to me... but it works...
Pointers, thoughts, opinions?
I see, it looks like we might need to tweak rabl to adhere to an explicitly specified format more closely? Since you specified:
it follows that it should try and render the format as JSON rather than CSV. I will have to dig in more later to see if this can be fixed easily. Thanks for raising the issue.
If you want to make a failing test for it, I can tweak it to work because by the looks of it, I would've guessed you can pass in the format and it won't use the request_format method.
Rabl.render(object, template, :view_path => 'app/views', :format => :csv)
I'm seeing a very similar issue. It looks like Rabl::Engine#request_format is relying on request_params / context_scope.params to choose the format, rather than @_options[:format] that stores the format the user passed in. Then in Rabl::Partials#fetch_rails_source it uses that for the source_format, with the result that rabl partials aren't found when I try to use them via gon.
I think that Rabl::Engine#request_format should take @_options[:format] into consideration if it's been set. Hope this gets someone closer to fixing this.