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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:44:07+00:00 2026-05-13T00:44:07+00:00

I have a little bit of trouble creating a menu in Rails. In ApplicationController

  • 0

I have a little bit of trouble creating a menu in Rails. In ApplicationController I have a set_menu method:

def self.set_menu(menu, options = {})
  # ...
end

This is called from each controller like this:

class UsersController < ApplicationController
  set_menu :users

  # ...
end

In set_menu, I need to create a variable that I later can reach in a helper method to find out which of the menu items that is the active one. I got this working by using a class variable. This worked fine in development, but it turns out that Rails caches this variable in production, so the active menu never changed.

So, how do I in set_menu create a variable that I can reach from a helper method and that production stage does not cache?

  • 1 1 Answer
  • 1 View
  • 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-13T00:44:07+00:00Added an answer on May 13, 2026 at 12:44 am

    Instance variables are shared between the controller and the view, including helpers.

    class ApplicationController
    
      def self.set_menu(menu, options = {})
        before_filter(options) do |controller|
          controller.send(:set_menu, menu)
        end
      end
    
      # ...
    
    
      protected
    
        def set_menu(menu)
          @menu = menu
        end
    
    end
    
    # in your view
    <%= @menu %>
    

    If you want to create more complex navigation menu, have a look at my Tabs On Rails Gem.

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

Sidebar

Related Questions

its a little bit hard to understand. in the header.php i have this code:
I have a repeater of div's that look a little bit like this: <div
I'm having a little bit of trouble implementing the following method while handling the
I'm have a little bit of trouble storing and accessing a multidimensional array from
I have a little trouble understanding the security bit around JSON, because often things
I am having a little bit trouble with the following. I have multiple form
I have this little bit of code that I can't quite work correctly. The
I have little bit longer question for you - but hope answer will be
I have a little bit seen the representation of an array in memory with
I have a little bit of Javascript that almost works correctly. Here's the code:

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.