Ruby woes: NameError and uninitialized constant

The thing I hate most about learning a new programming language is the time it takes to do the simplest things… something goes wrong and it takes hours to figure it. Sure, it’s worth it once you know but boy do I hate that time consuming learning process.

Meet today’s problem.

NameError in StoryController#index
uninitialized constant StoryController::Story
RAILS_ROOT: C:/Documents and Settings/sroot/My Documents/NetBeansProjects/scaffoldlearning
Application Trace | Framework Trace | Full Trace
C:/InstantRails-1.7-win/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:478:in `const_missing’
app/controllers/story_controller.rb:5:in `index’

Having spent 6 hours, googled as many variations as possible, I’ve finally tracked the problem is something to do with activesupport-2.0.2. I know this only because an earlier ruby program I created following a tutorial works without problem using the same code. When I purposefully break the earlier program, it’s error reads:

NameError in StoryController#index
uninitialized constant StoryController::Storys
RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace
C:/InstantRails-1.7-win/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:477:in `const_missing’
#{RAILS_ROOT}/app/controllers/story_controller.rb:7:in `index’

A similar error message but on a different version of activesupport. Unfortunately I have no idea how to fix this (or downgrade my rails install, or know if it’s a good thing to downgrade my install – will that just break something else?), so that will now have to wait until tomorrow.


Comments

4 responses to “Ruby woes: NameError and uninitialized constant”

  1. Hey!!!

    Im having the EXACT same problem. Put together a simply ruby program in the attempt to learn relationships and it worked. Now doing the exact same thing in a different project and im getting an error that looks like this:

    NameError in PostsController#create

    uninitialized constant PortfolioPage::Post

    I know the error has something to do with this line:

    @post = @portfolio_page.posts.build(params[:post])

    but i cant seem to figure it out at all – please let me know if you find a solution…

    cheers!

  2. I think i figured it out.

    The problem is that you have a resource named Storys and rails is expecting it to be named in singular form i.e. Story

    Either try starting again, or if you have a lot to loose try this:

    migrate back to a version without Storys
    re-generate the resource Story (and make sure your set to overwrite any existing files)
    and then migrate back to the current version.

    that sorted it out for me!

    from one rails beginner to another…

    cheers!

  3. Thanks for sharing Salman, hopefully another Rails newbie will save some time.

    1. I think a newbie from the future just did. Thanks!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Search this site


Free apps

  • birthday.sroot.eu – Your birthday or other celebration date based on [years on other planets] / [how many seconds/days] / [how far you’ve travelled around the sun]
  • stampulator.sroot.eu – Calculates the combination and how many 1st, 2nd, large 1st and large 2nd class Royal Mail stamps you need on large envelopes and packets

Recent posts


Archives


Categories