On Wed, Jun 24, 2015 at 12:42 PM, Godfrey Chan <[email protected]> wrote:

> The renderer is basically a "serializer" that takes an object and an
> options hash and returns a string. The reason it is not greppable and uses
> meta-programming is that we allow for a huge list of formats other than
> json, and this is a generic set up that works well for most formats
> (including, imo, json). Do we only try to look up a serializer object for
> `render json: ...`? What about `render xml: ...`? `render text: ...`? So
> long as we don't special-case json or a handful of things (imo, that seems
> like a bad idea), I think we will still end up with the same problem with
> metaprogramming and greppability.


Thanks Godfrey, I agree with you 100% here.  I was thinking of refining
this to something that took the render used into account.  I'm not exactly
proposing the bolded line there, but something like that would extend the
current logic.  In any case, sounds like a PR to document this would at
least be useful.  I'll take a look at your code and see what ideas are in
there

def _render_to_body_with_renderer(options)
  _renderers.each do |name|
    if options.key?(name)
      _process_options(options)
      method_name = Renderers._render_with_renderer_method_name(name)
 *     object =
Serializers._serialize_with_serializer_json(options.delete(name))*
      return send(method_name, object, options)
    end
  end
  nil
end

or a controller method that takes in the renderer name somehow (again, just
for illustration of that idea)

def get_serializer(resource, options)
*  renderer_method_name = options.delete(:renderer_method_name)*
*  fail if renderer_method_name.blank?*
  case renderer_method_name
  when :json then resource.as_json
  end
end


-Benjamin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to