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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:59:53+00:00 2026-05-15T20:59:53+00:00

I want to add a menu to my First Ever Rails Application. Nothing too

  • 0

I want to add a menu to my First Ever Rails Application. Nothing too complicated.
I’ve worked out that I should maybe reference it from application.html.erb, but after that I’m stuck.

Here’s what I’ve got so far (It’s not much)

<%= render :partial => "menu" %>

If I’m rendering a partial call “menu” in application.html.erb, where do I put the menu file, and what do I call it? Does it need to go in the controller of the view?

Can I call this partial from whichever layout subfolder I’m in?

Part II. If I want to show different content according to the view I’m in – how do I do this?

<body>
  <p>[<%= yield :menu %>]</p>
  <%= yield %>
</body>
</html>

I’m just learning Rails, so sorry about the stupid questions. Also, I’m interested in not only a solution, but also an idea of best practices.

  • 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-15T20:59:53+00:00Added an answer on May 15, 2026 at 8:59 pm

    In basic terms you are looking for the content_for helper. You put this inside your views which will then populate named blocks in partials or layouts such as :menu. You may elect, if you wish, to use partials to actually define the content for the content_for regions.

    In a view:

    <% content_for :menu do %>
      <ul>
        <li> ... </li>
        <li> ... </li>
      </ul>
    <% end %>
    

    or as:

    <% content_for :menu do %>
      <%= render :partial => "some_menu_content" %>
    <% end %>
    

    In the layout or partial:

    <div id="menu">
      <%= yield :menu%>
    </div>
    

    Watch this screencast from the Railscasts series for more information. It’s old but still applicable

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

Sidebar

Related Questions

Next to file menu i want to add a search menu that will have
I got a sub-menu that I add with values, I then want to set
I want to add menu at footer in Drupal. (e.g. contact us | sitemap
I have a one master Page. I want to add 3 Menu items to
I want to add a context menu to the tableview, more specifically I want
I want to add right click menu items to the explorer (i.e. when you
I want to add the option when the menu is called with the right
when i hover on div#new-menu-lower ul.menuul li.menuli i want to add display block to
My css3 animated menu is working pretty well. But now i want to add
Suppose you want to dynamically add to a HTML menu, where the menu HTML

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.