Created
December 12, 2012 08:20
-
-
Save basgys/4266041 to your computer and use it in GitHub Desktop.
Rails - Render a partial in a different format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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