views:

55

answers:

1

Before Rails 3 I used to set a title instance variable in my controller actions and then use <%=@title%> in my layouts.

But in Rails 3 they have included a helper method

    def title(page_title)
      @content_for_title = page_title.to_s
    end

and in the application.html erb

<title><%= yield(:title) %></title>

This requires us to set title in view templates. Are there any advantages of doing it this way?

A: 

It will make your controllers clean, and best place for title is view, not controller. http://apidock.com/rails/ActionView/Helpers/CaptureHelper/content_for

content_for is rails way to pass html between templates. This schema is also convenient to include view specific javascripts (i.e. for WYSIWYG), or css.

Sławosz