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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:38:32+00:00 2026-05-24T22:38:32+00:00

I have several variables that I would like all controllers to access. So I

  • 0

I have several variables that I would like all controllers to access. So I defined them in my application_controller.rb :

      before_filter :initialize_vars

  def initialize_vars
    @siteTitle = "my title"
    @companyName = "company"    
  end

No problems there.
I wanted to do something similar with the logo so I created another method that was called with the before_filter as well.

  def logo
    image_tag("Logo.jpg", :alt => "Logo")
  end

one instance of the logo img should link to the site root so I called it with:

<%=h link_to logo, root_path %>

but it didn’t work in my layout! When I add my logo method to the application_helper.rb everything works perfectly. hhmmm.

what / where is the appropriate place for all this stuff? I mean just because I was able to make it work doesn’t make it right!

Should I define my instance variables (that I’m treating like global variables) in the application_controller and the logo method in my helper like I’ve done? I feel like I’m missing some fundamental understanding here of why they need to go in different places. I’m not sure if it’s HOW I’m calling the “logo” method or where I’m putting it. I’m going to play with how I’m calling and how I’ve written the logo method because I feel like both methods should go in the application_controller.

thoughts?

Thanks!

  • 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-24T22:38:32+00:00Added an answer on May 24, 2026 at 10:38 pm

    Functions that are related to rendering views are placed in helper files.
    They typically generate HTML content. If the helper method is used across the app in many places, put them in application_helper.rb, otherwise they have to be placed in corresponding helper files.

    As the instance variables you have is going to be accessed in many controllers, you can initialize them in application controller like you have.

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

Sidebar

Related Questions

I have several old 3.5in floppy disks that I would like to backup. My
On my web site I would like to have several sub-domains. Files that create
I would like to create a function that contains all text and constant. From
I would like to have several Cache objects in my application and I'd like
I have a table (table variable in-fact) that holds several thousand (50k approx) rows
I have a data frame with several variables. What I want is create a
I have a function which evaluates terms of a polynomial in several variables. The
I have several RequiredFieldValidators in an ASP.NET 1.1 web application that are firing on
We have several jobs that run concurrently that have to use the same config
Here's the setup: I have several tables that hold information for data objects which

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.