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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:21:08+00:00 2026-06-16T15:21:08+00:00

I have a rails application that has 2 menu in which the menus changes

  • 0

I have a rails application that has 2 menu in which the menus changes depending on what page the users are currently visiting. Is there any way to tell rails that if a user is visiting this controller, no matter if the visitor is on the index,edit,create,update,delete method?

I am currently using a helper like so it and it indeed a bit messy.

def which_page
  current_page?(root_path) || 
  current_page?(skate_movies_path) ||
  current_page?(new_skate_photos_path(@user)) || 
  current_page?(skate_photos_path) || 
  current_page?(skate_tricks_path)
end

In My view partial

 <% if which_page %>    
   <%= default_menu %> #upload, #photos, #trick-tips, #goals
 <% else %>
   <%= skate_menu %> #dashboard, #shared-videos, #profile
 <% end %>

The problem is this works but throughout the application I always find a page or two where it gives me a routing error. Any way to tell what controller the user is on and action without specifying ever action?

  • 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-06-16T15:21:09+00:00Added an answer on June 16, 2026 at 3:21 pm

    You could define a before_filter in your ApplicationController and name it set_menu

    class ApplicationController < ActionController::Base
      before_filter :set_menu
    
      protected
    
      def set_menu
        @menu = 'default'
      end
    
    end
    

    Then in each controller that you want to show a different menu for you would override set_menu, for example:

    class SkateMoviesController < ApplicationController
    
       protected
    
       def set_menu
         @menu = 'skate'
       end
    
    end
    

    you could use the helper method action_name in set_menu to access the current action in the controller.

    Then in your views:

    <% if @menu == 'default' %>
      <%= default_menu %>
    <% else %>
      <%= skate_menu %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rails application that has three different types of users and I
I have an application that has different data sets depending on which company the
I have a Rails application that unfortunately after a request to a controller, has
I am working on a Rails application that has user authentication which provides an
I have a Ruby on Rails application that I'm developing on my computer, which
I currently have a Ruby (Rails) application that needs to make a lot of
I have a rails application on a shared server that also has a decently
I have a Rails application that has to co-exist with a very old legacy
I have a Rails application that has file uploading. Once the file is uploaded
I have a Ruby on Rails application that has two active environments, Stage and

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.