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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:16:14+00:00 2026-05-25T11:16:14+00:00

This is really starting to drive me crazy; I’ve spend a solid two hours

  • 0

This is really starting to drive me crazy; I’ve spend a solid two hours on this and I just can’t figure it out! What I am trying to do is use ERB in a YAML file to include a rails route in the YAML file. Long story short this will be read back later to make a semanic menu from the YAML file. I am loading the YAML file (with ERB) in an initializer _load_config.rb and the code which loads it looks like this:

menu_yml= "#{Rails.root}/config/menu.yml"
config = YAML.load(ERB.new(IO.read(menu_yml)).result)
MENU_CONFIG = config

In the YAML file menu.yml I have something to the effect of:

logged_in:
  dashboard:
    text: "Dashboard"
    url: <%= url_for dashboard_path %>

The problem is that <%= url_for hasboard_path %> throws and error:

(erb):4:in `<main>': undefined local variable or method `dashboard_path' for main:Object (NameError)

From much debugging I presume that this is due to routes being loaded after this initializer. Any suggestions as to how to fix this is much appreciated!

P.S. This is using Rails 3.1.rc5

  • 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-25T11:16:15+00:00Added an answer on May 25, 2026 at 11:16 am

    The reason you are getting that error is that url_for is a helper for ActionView and therefore not accessible when the initializer runs – it won’t work if called from models or the console, so the problem isn’t necessarily that routes are being loaded after that initializer.


    I’m not sure exactly how you’re dashboard route is setup and why it needs to be dynamically tied to menu.yml. Assuming it doesn’t have any params sent through the URL(since no args are passed into url_for’) and you are using match for routing: Having a global or environment variable that is referenced by routes.rb and menu.yml might give the functionality you need.

    boot.rb

    require 'rubygems'
    
    DASHBOARD_URL = '/dashboard'
    ...
    

    routes.rb

    match DASHBOARD_URL => 'dashboard#index'
    

    menu.yml

    logged_in:
      dashboard:
        text: "Dashboard"
        url: DASHBOARD_URL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This really shouldn't be hard, I just can't figure out how to do it.
I'm feeling silly that I cannot figure this out, but it's really starting to
This really should be easy, but I just can't work it out myself, the
OK this is starting to drive me crazy! I am trying to do some
This is really strange and I can't seem to figure out why it won't
Probably a really simple one this - I'm starting out with C# and need
This is really starting to confuse the hell out of me. When do I
Okay this is probably a really dumb question, however it's really starting to hurt.
This really, really urks me, so I hope that someone can give me a
This really seems like a bug to me, but perhaps some databinding gurus can

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.