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

  • Home
  • SEARCH
  • 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 3986738
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:03:01+00:00 2026-05-20T06:03:01+00:00

I have been creating my first site using Rails on and off for a

  • 0

I have been creating my first site using Rails on and off for a few weeks now and constantly picking up new nuggets of info, loving it more everyday. This site has helped me immensely, so thank you.

I encountered a scenario when trying to set my META tags, universally using one (global) function, trying to make it DRY and all!

Is the following good or bad practice? Have I overlooked something obviously easy I could have done instead?

Now the following works a dream and seems very logical to me, but is it bad practice?

In application_controller.rb :

def make_meta_title name

  title = name

  if [params[:page]]
    title << " page " + params[:page]
  end

  title << " | My Site Name"

end

In my products_controller.rb :

def show
  ...
  @meta_title = make_meta_title(@products.name)
end

Then in my view

<title><%= @meta_title %></title>

The output

Blue widget | My Site Name

or

Blue widget page 2 | My Site Name

p.s. Please don’t comment on my syntax, this is from memory as I’m on a different computer at the moment, it’s along these lines though!

  • 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-20T06:03:02+00:00Added an answer on May 20, 2026 at 6:03 am

    The application_controller.rb should contain stuff that benefits from being shared with all other controllers in your application… There are several typical use-cases for this (like some shared filters – e.g. authentication).

    Now in this specific case you could use a combination of some stuff in your controller and a helper method. The controller would store the META you want to add to your pages, and the helper would generate the markup for these… Then you’d add that in your layouts/application.html.erb (or whatever templating engine you use)…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been creating a website with Ruby on Rails, and will be hosting
I have been in both situations: Creating too many custom Exceptions Using too many
I have been creating Unit tests like crazy and find that I'm often having
I have been tasked with creating a program that will generate an amortization schedule.
I have been tasked with creating a program what will create take files in
I have been tasked with creating a reusable process for our Finance Dept to
For my assignment I have been assigned the task of creating a DTD for
We have been using CruiseControl for quite a while with NUnit and NAnt. For
Have been looking at the MVC storefront and see that IQueryable is returned from
Have been studying the file system related classes of Adobe AIR 1.5, but so

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.