Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8478029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:37:55+00:00 2026-06-10T18:37:55+00:00

I am following railscasts to update custom page title and realized that it doesn’t

  • 0

I am following railscasts to update custom page title and realized that it doesn’t work anymore. So, i updated the code as follows based on the comments. I see ‘My Services -‘ if i do not set the title, whereas i expect it to contain default title value set. Any insights please?

In application.html.erb:

<!DOCTYPE html>
<html>
<%= render 'layouts/head' %>
<!-- <body> included in yield -->
  <%= yield %>
<!-- </body> -->
</html>

In _head.html.erb

<head>
  <title>My services - <%= yield(:title) %> </title>
</head>

In home.html.erb [Intentionally not setting title to see default value]

<body></body>

In application_helper.rb

  def title(page_title, default="Testing")
    content_for(:title) { page_title || default }
  end

In application_helper.rb, I also tried the following solution:

  def title(page_title)
    content_for(:title) { page_title || default }
  end

  def yield_for(section, default = "Testing")
    content_for?(section) ? yield(section) : default
  end

Any insights please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:37:56+00:00Added an answer on June 10, 2026 at 6:37 pm

    I think you should simplify:

    <title>My services - <%= page_title %> </title>
    

    application_helper.rb

    def page_title
      if content_for?(:title)
        content_for(:title)
      else
        "Testing"
      end
    end
    

    Now, I don’t think you actually want “Testing”… Really, I think you just want to not see the “-” at the end of your html page titles. So why not:

    <title><%= html_title %></title>
    
    def html_title
      site_name = "My services"
      page_title = content_for(:title) if content_for?(:title)
      [site_name,page_title].join(" - ")
    end
    

    You’ll either see:

    <title>My services</title>
    

    or if you set the title like so:

    <%= content_for(:title) { "SuperHero" } %>
    

    You’ll see:

    <title>My services - SuperHero</title>
    

    #content_for? is defined as:

    #content_for? simply checks whether any content has been captured yet using #content_for Useful to render parts of your layout differently based on what is in your views.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm following a Rails cast to implement subscription billing. It's here: http://railscasts.com/episodes/288-billing-with-stripe My code
I'm following the Railscasts tutorial on using OpenID with AuthLogic . This command: $
I am following Ryan Bates railscasts I18n Internationalization and hitting a problem/question. I am
I'm following Railscast 88 to create a dynamic dependent dropdown menu. http://railscasts.com/episodes/88-dynamic-select-menus I'm rendering
Following code produces a nested array as a result for keys containing three items:
Following code takes like 2500 milliseconds on an i7-*3.4 GHz windows-7 64-bit computer to
Following code worked fine abstract class FunctionRunnable<V> implements Runnable { protected abstract V calculate();
Im following the casts http://railscasts.com/episodes/314-pretty-urls-with-friendlyid?autoplay=true on friendly_id Having a user model with field login
I'm following this tutorial: http://railscasts.com/episodes/253-carrierwave-file-uploads or atleast I want to but would like to
I'm building a one page form that will create a model and it's relations.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.