Question

I'm new to rails and working through Hartl's tutorial. Everything was fine until I tried to do the tutorial a second time and created another project trying to use the latest version of rails. When I try to load the rails server from the app folder I get the following error.

$ rails s
=> Booting WEBrick
=> Rails 4.0.4 application starting in development on
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/Users/sierra/Desktop/sample_app_2/config/environments/development.rb:1:in
  `<top (required)>': undefined method `configure' for
  #<SampleApp2::Application:0x00000101a74610> (NoMethodError)

My Gemfile is directly from the Hartl tutorial:

source 'https://rubygems.org'
ruby '2.1.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.4'

group :development, :test do
  gem 'sqlite3', '1.3.8'
  gem 'rspec-rails', '2.13.1'
end

group :test do
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.1.0'
end

gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'rails_12factor', '0.0.2'
end
Was it helpful?

Solution

I resolved it by doing following step.

Step 1: go to Project_Root_Directory/config/environment/development.rb

Change this line

Rails.application.configure do

To

Your_Rails_Application_Folder_name::Application.configure do

For example my rails project folder name is 'Spree_demo' so Your_Rails_Application_Folder_name in the following line:

Your_Rails_Application_Folder_name::Application.configure do

will be replaced as

SpreeDemo::Application.configure do

Note: See underscore in your application folder name it gets removed.

Hope it works for you guys.

OTHER TIPS

First set Ruby version before Rails new

I had the same problem and I tried the answer given and it had no impact. I even tried changing the name to get rid of the underscore, and it had no impact.

The problem is that you did this:

$ rails new app_name

But your ruby version was probably 2.1.1 or something else. You want to do:

$ rvm 2.0.0

BEFORE you run the new app, and then when you set 2.0.0 in your Gemfile (as Hartl recommends) it falls into place.

I don't know WHY this works, and I hope someone will shed light on it, but I can tell you that this worked better than the answer that is currently in the lead.

That happened to me too. The problem was that I used one version of Rails to create the project. Then I changed the Gemfile to use another version of Rails and the system was using it to scaffold or run the server. Newbie problem! Using the same version consistently should solve the problem. :-)

I posted a (probably way too long) answer in a similar question: rails - NoMethodError: undefined method `configure' for FirstApp. This thread actually started me on the way to my eventual solution, so I thought I'd post here as well just in case it's helpful to anyone else.

From what I can tell, the problem occurs when the app/config/initializers/development.rb (and production.rb) files are generated for a new project using some newer versions of Rails (I'm not sure in which version it started, I only tested Rails 4.1.4). Mr. Hartl uses Rails 4.0.8 for his tutorial, and that's the highest version I tested in which the new syntax doesn't occur.

In Rails 4.1.4, and maybe some other versions after 4.0.8, the first line in those files is generated as Rails.application.configure.do rather than, using a project called sample_app as an example, SampleApp::Application.configure.do as in 4.0.8.

I'm new to Rails so I don't know why this syntax changed in newer versions. I'm assuming it's intentional and somehow better than the old way. Most likely, Mr. Hartl will take it in to account in future editions of his tutorial that are updated for versions of Rails which include this change.

Until then, see my other answer in the question I mentioned above for a more thorough explanation of how I got around it on Windows 7, but the tl;dr of it is:

Make sure you're using the version of Rails specified for the tutorial (4.0.8) in your local repository/root development directory before you create your new project. Updating your Gemfile after creating the project is still important, but it won't solve this problem if the files themselves were generated with a newer version of Rails. You'll have to go in and edit that line manually in that case, as other users have suggested.

I had this issue when I messed around with my Gemfile. For example I have created the app using rails 4.0.2 or something like that then due to some errors I changed it to 4.1.1 that change cause this exact same problem in both development and production

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top