Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • 35
    It's worth noting that this won't work with rails view caching. In rails 3 content_for is smart enough to work correctly with caching (see selected answer). Commented Nov 15, 2011 at 10:41
  • 4
    shouldn't variables be set inside the controller ? Commented Jun 7, 2013 at 15:45
  • 2
    @SajjadMerchant generally I agree, yes variables should be set in the controller. In this case the template feels more appropriate though because you're specifying an attribute specific to the appearance of the page. It's also possible for a controller action to be used by two different views (not that this happens very often, I'm using it to illustrate how tightly bound the title is to a particular template). Commented Jun 9, 2013 at 10:35