Set Different Title for each Page

1. Create a helper method in application_helper.rb

    # Returns the full title on a per-page basis.
    def full_title(page_title)
      base_title = "Base Title"
      if page_title.empty?
        base_title
      else
        "#{base_title} | #{page_title}"
      end
    end

2. In application layout:

 <%= full_title yield(:title) %>

3. Now where ever you want to use different title write this code in view file:

  <% provide :title, 'Sub Title' %>

Now it will show “Base Title | Sub Title” , If you don’t use last step then it will display title as “Base Title”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s