Never been to DZone Snippets before?

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

Render a partial to an instance variable (See related posts)

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.

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

Comments on this post

mattm posts on Jun 19, 2005 at 12:49
or in the view you could just call render_partial
kelyar posts on Apr 10, 2006 at 20:12
i think you can also use render_to_string
@content_for_navbar = render_to_string :partial => "layouts/public_navbar"

You need to create an account or log in to post comments to this site.


Click here to browse all 4836 code snippets

Related Posts