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 1102191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:08:53+00:00 2026-05-17T01:08:53+00:00

I don’t like the way rails does page titles by default (just uses the

  • 0

I don’t like the way rails does page titles by default (just uses the controller name), so I’m working on a new way of doing it like so:

application controller:

def page_title
    "Default Title Here"
end

posts controller:

def page_title
    "Awesome Posts"
end

application layout:

<title><%=controller.page_title%></title>

It works well because if I don’t have a page_title method in whatever controller I’m currently using it falls back to the default in the application controller. But what if in my users controller I want it to return “Signup” for the “new” action, but fall back for any other action? Is there a way to do that?

Secondly, does anyone else have any other ways of doing page titles in rails?

  • 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-05-17T01:08:53+00:00Added an answer on May 17, 2026 at 1:08 am

    I disagree with the other answers, I believe the title shouldn’t be set per action, but rather within the view itself. Keep the view logic within the view and the controller logic within the controller.

    Inside your application_helper.rb add:

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

    Then to insert it into your <title>:

    <title><%= content_for?(:title) ? content_for(:title) : "Default Title" %></title>
    

    So when you are in your views, you have access to all instance variables set from the controller and you can set it there. It keeps the clutter out of the controller as well.

    <%- title "Reading #{@post.name}" %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't be scared of the extensive code. The problem is general. I just provided
Don't know how to google for such, but is there a way to query
Don't be frightened, its a very basic code. Just wanted to check with you
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't know a whole lot about streams. Why does the first version work using
Don't think my virtualhost is working correctly. This is what I have inside of
Don't ask why, but is there any way to suppress a failed linking error?
Don't know why, but sometimes LocationManager is still working also after closing application. I
don't understand: in my controller: @json = User.all.to_gmaps4rails do |user| \Title\: \#{user.email}\ end in
I don't want to use the Default Satchmo search listener. I've created my own

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.