Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

render :partial should accept :format option #4841

Closed
jfirebaugh opened this Issue · 8 comments

7 participants

@jfirebaugh

It's currently difficult to render a partial with a different format from the current response:

http://stackoverflow.com/questions/339130/how-do-i-render-a-partial-of-a-different-format-in-rails
http://stackoverflow.com/questions/2459787/in-rails-3-how-does-one-render-html-within-a-json-response

render :partial => <partial>, :format => :html should work how you would expect.

@timhaines

This works: render :partial => <partial>, :formats => [:html]

It would be more natural to specify :format => :html if you only want to specify one.

@josevalim
Owner

I am fine with :formats accepting a symbol and not an array, but :-1: for having another option just to accept a symbol.

@spastorino
Owner

you could do render :partial => <partial>, :formats => :html

@spastorino spastorino closed this
@dnagir

The problem with the formats option is that partials rendered from others will still use the current action's format.

That means it is impossible to render that renders another one.

Example:

index.html
  |
  -> index.json
      |
      -> post.json (this is not possible to render because the format is html)

How do you deal with it?

@route

@dnagir I came across this too and provided a patch #6626, unfortunately it cannot be backported to 3.2. I have no idea how to fix this without monkey patching for current version.

@dnagir

Thanks @route. No backporting means we'll get sooner onto rails 4 :)

For now I'm using this workaround.

@route

No problem, I'm waiting for this event too ;)

@fotanus

:+1: for render with :format, took me some hours for something that stupid, since it is totally legible and it is a good idea test each view formats separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.