Smart page titles in Ruby on Rails

Having separate titles for each page in Rails application is a very common requirement and yet RoR does not provide any built in ways to deal with it. I am going to present you with some handy code that can solve this problem without use of gems.

There are going to be 3 ways to define a page title:

  • For tho whole controller.
  • For a specific action inside a controller.
  • Implicitly from a controller name.
Last is gonna be especially useful, you can just drop the following code into your application and have reasonably good titles.

So lets add code to our parent ApplicationController:

And reference page title in our layout:

After that setting pages titles is extremely easy. You don't even have to do it if you are naming your controllers properly.


  1. The team excelled at thoroughly understanding the requirements web agency marketing. They met every guideline and brainstormed creative solutions.

  2. Their team communicated on Slack regularly and had a smooth workflow. The leadership and understanding were very impressive.
    brand building agency

  3. The team graciously modified its preferred mobile design agencyworkflow to align with client preferences, and they fearlessly accepted all challenges and tasks

  4. The team was dedicated and professional, maintaining regular communication, and understanding the project brief with ease.
    brand building agency


Post a Comment

Popular posts from this blog

Turbocharge HTTP requests in Ruby

Faster Google Maps load times

Ruby on Rails optimization techniques