DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Render A Partial To An Instance Variable

  • submit to reddit
        Normally, if you call "render_partial" within a controller, nothing but the partial will be rendered.

Occasionally, it is useful to render a partial to an instance variable as a string so that the view can still be rendered as normal, and the string can be passed in to the view.

  @content_for_navbar = @template.render_partial 'layouts/public_navbar'


Snippets Manager replied on Fri, 2005/12/16 - 3:52pm

i think you can also use render_to_string @content_for_navbar = render_to_string :partial => "layouts/public_navbar"

Snippets Manager replied on Mon, 2012/05/07 - 2:12pm

or in the view you could just call render_partial