Mar 16, 2009

Quick Tip: Solve uninitialized constant ApplicationController in Rails 2.3

If you've just upgraded your Rails stack to 2.3 you may be seeing a strange error:

uninitialized constant ApplicationController


Turns out, among the Major changes that came along with the latest Release of Ruby on Rails, there were a few minor ones too. One of those is that the application controller is no longer called application.rb Now it's referred to as application_controller.rb.

In effect, to solve this problem, just rename the file. Or, as Liam points out in the comments below, run:

rake rails:update



Be sure to update your server stack before deploying. Obviously if you rename the file to get it working on Rails 2.3 and upload to a Rails 2.2 server you'll be in trouble. Don't forget that Rails 2.3 also requires a new version of Phusion Passenger!

16 comments:

  1. Vince, you are a total star. Thank you thank you!

    I notice that when I do this, I also get this error:
    Missing layout layouts/_common-head.erb in view path app/views

    Sure enough, the "minor changes" that completely stopped my development efforts all morning also include adding leading underscores to views.

    This latest "improvement" was nearly as irritating as discovering the ":dasherize => false" setting necessary to export underscored table names correctly into XML for Flex3 apps.

    Rails is a joke as a production tool, not because it can't do the job, but because of the way the Rails developers inelegantly handle change. I'm sure they have answers to that challenge, but fact is there are better ways to implement changes, and Rails simply doesn't want to grow up and adopt them.

    I only use it b/c of a legacy system at my job. It's a great prototyping tool, but I cannot imagine using this in a production environment where the lost revenue for an hour of downtime exceeds the value of my annual wages.

    I can't wait to get out of a Rails environment and back to good old reliable LAMP. This was just one more nail in the coffin.

    Thanks again for your post. You saved me a lot of time figuring out a deeply disappointing decision by the Rails development team.

    ReplyDelete
  2. John,

    The leading underscore on a view indicates that the view is a partial. This is nothing new.

    ReplyDelete
  3. Wow great man got it working for me
    Thanks a lot and Hats off for you

    ReplyDelete
  4. Thanks a lot! That was a real help.
    Works like a charm.

    ReplyDelete
  5. running `rake rails:update` is a better way to fix this issue- it'll insure your entire config is updated to work with the current rails version.

    ReplyDelete
  6. Thanks, this was driving me crazy. No wonder it led John to throw quite a fit.

    ReplyDelete
  7. [Sigh] You would have thought that the rails team would have put details of a change that breaks code like this somewhere reletively prominant on their site. I am sure that for ppl working heavily with rails they would find this info out quick enough, but for casual users (e.g. using rails for occasional Intranet mods etc) then they need details of this type of change putting into a highly visible area.

    ReplyDelete
  8. Thanks for the update! This was the only reference to this problem I could find. Suprisingly the Rails console tells about all sorts of non-fatal deprecation warnings. But this one fatal issue goes through silently, breaking all in its path.

    Rails is very much production ready (unlike some other comments), but not upgrade friendly!

    ReplyDelete
  9. You ARE a STAR! Saved me a few hours of hunting around for the proper answer. Thanks

    ReplyDelete
  10. Hero. Quickest fix ever. As the person above says, this could have taken hours.

    ReplyDelete
  11. Thanks for the tip!

    ReplyDelete
  12. Thank you, You + Google = Genius

    ReplyDelete
  13. Many thanks, that was perfect - long may this page continue at the top of the Google search results!

    ReplyDelete