Skip to content

Instantly share code, notes, and snippets.

@basgys

basgys/gist:4266041

Created Dec 12, 2012
Embed
What would you like to do?
Rails - Render a partial in a different format
# Render a partial in a different format
#
# Parameter : String or Array
# Usage :
# <% with_format('html') do %>
# <%= render(partial: 'partial') %>
# <% end %>
def with_format(formats)
original_formats = self.formats
self.formats = formats.kind_of?(Array) ? formats : [formats]
result = yield
self.formats = original_formats
return result
end
# See http://stackoverflow.com/questions/339130/how-do-i-render-a-partial-of-a-different-format-in-rails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.