rails/rails — pull request #13681 by iainbeeston (2014-01-12 13:31:53+00:00)
Title: Made it possible to specify an explicit format or layout when passing an object to RenderHelper#render

Problem
-----------

When you call `<%= render @something %>` in an action view template, you can pass a hash of options, all of which are interpreted as locals in the appropriate partial for `@something`. If you'd like to be able to render `@something` in a format that's different to that of the parent template (eg. you have a html template but want to render `@something` as xml, or json) then the only way to do this is to call render like this:

```
<%= render partial: @something.to_partial_path, object: @something, formats: :xml %>
```

Which seems very verbose and unintuitive. I would have expected `render` to understand something like this instead:
```
<%= render @something, formats: :xml %>`
```
But it does not (`formats` is passed to the partial for `@something` as a local and the format is unchanged from the calling view).

Solution
-----------

This pull request makes the `render` call above work, by interpreting arguments to `render` named `formats` or `layout` as options to `render` instead of locals. It makes the api for `render` more intuitive, at the expense of adding special case behaviour.