1

I've just started doing the "Ruby on Rails Tutorial", from Michael Hartl. I've created a new project with:

rails new first_app

Then he had me change the Gemfile from:

source 'https://rubygems.org'

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.1'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster.
# Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.0.1'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

To this:

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

gem 'rails', '4.0.5'

group :development do
  gem 'sqlite3', '1.3.8'
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 'jbuilder', '1.0.2'

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

Now when I try to run rails server, I get this error:

PS C:\Users\Thomas\rails_projects\first_app> rails server
=> Booting WEBrick
=> Rails 4.0.5 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
C:/Users/Thomas/rails_projects/first_app/config/environments/development.rb:1:in `<top (required)>': undefined method `c
onfigure' for #<FirstApp::Application:0x2a2bae8> (NoMethodError)
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.5/lib/active_support/dependencies.rb
:229:in `require'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.5/lib/active_support/dependencies.rb
:229:in `block in require'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.5/lib/active_support/dependencies.rb
:214:in `load_dependency'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.5/lib/active_support/dependencies.rb
:229:in `require'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.5/lib/rails/engine.rb:591:in `block (2 le
vels) in <class:Engine>'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.5/lib/rails/engine.rb:590:in `each'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.5/lib/rails/engine.rb:590:in `block in <c
lass:Engine>'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.5/lib/rails/initializable.rb:30:in `insta
nce_exec'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.5/lib/rails/initializable.rb:30:in `run'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.5/lib/rails/initializable.rb:55:in `block
 in run_initializers'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/tsort.rb:150:in `block in tsort_each'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/tsort.rb:183:in `block (2 levels) in each_strongly_connected_com
ponent'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/tsort.rb:210:in `block (2 levels) in each_strongly_connected_com
ponent_from'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/tsort.rb:219:in `each_strongly_connected_component_from'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/tsort.rb:209:in `block in each_strongly_connected_component_from
'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.5/lib/rails/initializable.rb:44:in `each'

        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.5/lib/rails/initializable.rb:44:in `tsort
_each_child'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/tsort.rb:203:in `each_strongly_connected_component_from'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/tsort.rb:182:in `block in each_strongly_connected_component'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/tsort.rb:180:in `each'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/tsort.rb:180:in `each_strongly_connected_component'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/tsort.rb:148:in `tsort_each'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.5/lib/rails/initializable.rb:54:in `run_i
nitializers'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.5/lib/rails/application.rb:215:in `initia
lize!'
        from C:/Users/Thomas/rails_projects/first_app/config/environment.rb:5:in `<top (required)>'
        from C:/Users/Thomas/rails_projects/first_app/config.ru:3:in `require'
        from C:/Users/Thomas/rails_projects/first_app/config.ru:3:in `block in <main>'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
        from C:/Users/Thomas/rails_projects/first_app/config.ru:in `new'
        from C:/Users/Thomas/rails_projects/first_app/config.ru:in `<main>'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'

        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_op
tions_from_config'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.5/lib/rails/commands/server.rb:48:in `app
'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.5/lib/rails/commands/server.rb:75:in `sta
rt'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.5/lib/rails/commands.rb:76:in `block in <
top (required)>'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.5/lib/rails/commands.rb:71:in `tap'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.5/lib/rails/commands.rb:71:in `<top (requ
ired)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

I know the error occurs from changing the Gemfile because it works before I change it. I want to follow Michael as closely as possible. The only different is that I'm using Ruby 1.9.3 and he is using Ruby 2.0, though in the book he said if not using 2 just change that in the Gemfile which I did.

ekremkaraca
  • 1,453
  • 2
  • 18
  • 37
Tom
  • 21
  • 3

5 Answers5

1

You need change in app/config/initializers/development.rb line

Rails.application.configure do

to

YourApp::Application.configure do

but you will see the error:

Internal Server Error You must set config.secret_key_base in your app's config

To solve this problem you should generate a rnd secret key

$ rake secret

then create file config/initializers/secret_token.rb and put into this file

YourApp::Application.config.secret_key_base = 'YOUR_SECRET_KEY'

where YOUR_SECRET_KEY is prev generated and all goes ok.

The reason is because of new convention to store secret key (Upgrading from Rails 4.0 to Rails 4.1 docs)

P.S. Pay attention to file config/secrets.yml.

bobcat13
  • 56
  • 5
1

You are declaring ruby '2.0.0' at the begin of the Gemfile but you are using 1.9.3 so it will fail when trying to detect it. Change to ruby '1.9.3'

Also you might need to run bundle in order to install the gems.

Jorge de los Santos
  • 4,583
  • 1
  • 17
  • 35
0

Have you tried removing the ruby line completely? I don't usually have this line in my gemfile

Michael Moulsdale
  • 1,488
  • 13
  • 34
0

This is the error you're receiving:

C:/Users/Thomas/rails_projects/first_app/config/environments/development.rb:1:in `<top (required)>': undefined method `configure' for #<FirstApp::Application:0x2a2bae8>

It basically means you have an error on line 1 of the file /config/environments/development.rb

--

You mention the error disappears when you change your Gemfile. I suspect the issue is you've not got Ruby 1.9.3 installed on your system, confusing Rails & preventing it from loading

My recommendation is to (re)install Ruby 1.9.3 or Ruby 2.0.0 on your system

Richard Peck
  • 76,116
  • 9
  • 93
  • 147
  • Thanks Rich, I used rail yards quick installer. I have reinstalled ruby a few times and still no luck. When i type ruby -v, it says ruby 1.9.3 is installed – Tom May 18 '14 at 06:58
  • Hmm okay, can you detail which line in your `Gemfile` you're getting the error from? That would be a big help – Richard Peck May 18 '14 at 07:00
  • Also, are there any dependencies you're using which rely on Ruby 2.0? – Richard Peck May 18 '14 at 07:00
  • I'm not sure how to find that. I watch two ruby items pop up in task manager when i hit rails server, and then they disappear. Everything seems to work up until rails server. I get the feeling that there are dependencies, all the gems are very version specific. Maybe ill just switch to version two even though he recommends 1.9.3, and then puts 2 code haha. – Tom May 18 '14 at 07:09
  • What about your Gemfile? Which line allows you to run the server? – Richard Peck May 18 '14 at 07:10
  • I had rails at version 4.1.1 installed globally. I replaced my Gemfile with what was shown in the book, so it loaded rails 4.0.8 locally. This gave me that error too. I just switched the rails version in the Gemfile to 4.1.1, bundle update and it worked again. – dardub Jul 22 '14 at 17:43
0

I had the same issue.

Check your rails version by

rails -v

Then in your Gemfile of your app change make sure you have the version of rails with accordance to the one you have on your computer in my case it was:

gem 'rails', '4.1.1'

Now finally run

bundle update bundle install

Now you should be able to run your server.

Biscuit
  • 21
  • 5