I had this exact same issue just recently when setting up someone's computer for the Rails Tutorial after reformatting it for them. I was using the RailsInstaller.com Windows executable to install Rails on Windows 7, but I imagine the actual cause of, and solution to, the error is the same on Linux/OS X.
The problem in my case was that the current RailsInstaller executable installs Rails 4.1.4 (if there's a way to choose which version during the installation, I didn't see it). The RailsTutorial.org tutorial is meant to work with Rails 4.0.8, at least until Mr. Hartl updates it.
Updating your Gemfile in your project directory to use Rails 4.0.8 after creating the first_app project with rails new first_app
won't fix the issue, because the problem occurs during the generation of the app/config/initializers/development.rb file which, by default, uses the newest version of Rails that's installed in your local repository.
I'm still mostly a novice to Rails so I don't know what changed, or why, but some update between Rails 4.0.8 and Rails 4.1.4 caused development.rb (and production.rb) to be generated with different syntax.
Making the change to the first line of those files to say FirstApp::Application.configure.do
instead of Rails.application.configure.do
, as others have suggested, will fix the compile error. However, having to manually change that line for every project didn't feel right to me.
I was able to make it generate the file correctly in two different ways:
1) Create the rails project specifying the version of Rails to use surrounded by underscores. For example, rails _4.0.8_ new first_app
. You have to have that version of Rails installed for it work, obviously. You can see all versions of that gem that are installed using the command gem list -d rails
. If you don't have the correct version, use gem install rails --version 4.0.8
to install it.
2) Navigate to the directory from which you'd run the rails new
command when starting a new project, and from there manually uninstall from the local gem repository any versions of Rails and its dependencies above version 4.0.8. To do this, you use the command gem uninstall <gem name> --version <version number>
. You could also use that command without including the version parameter, then use gem install rails --version 4.0.8
afterwards, which will install Rails and the matching version of its dependencies as well.
This was more time consuming but it's what I ended up doing. In my case, the gems I did this for were actionmailer, actionpack, activemodel, activerecord, activesupport, rails, and railties. Once the highest version for all of those gems was 4.0.8, generating a new project used Rails 4.0.8 by default and development.rb was created using the correct syntax.
One thing to mention for RVM users (I don't use it myself, since I'm on Windows, so I didn't test this): Double check which version of Rails RVM is set to use in your root development directory (the directory you'd be in when typing rails new
), since that's the version that it will use when generating a new project. Even if you set RVM to use Rails 4.0.8 once inside your new project folder, it won't fix the issue since the files themselves were still generated with whatever version of Rails RVM is using in the root directory.
Again, I'm still a novice to Rails so hopefully someone more knowledgeable than I can explain what's going on with the changes to development/production.rb between Rails 4.0.8 and 4.1.4. In the meantime, though, if you're trying to get set up for the RailsTutorial.org book and are encountering this error, these are two possible methods to fix it.