7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rails server実行時にエラーがでて起動しない時の解決方法

Posted at

問題

rails server

上記のコマンドを実行時に次のようなエラーが出た。

vagrant@precise64:~/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
/home/vagrant/first_app/config/environments/development.rb:1:in `<top (required)>': undefined local variable or method `first_app' for main:Object (NameError)
	from /var/lib/gems/1.9.1/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `require'
	from /var/lib/gems/1.9.1/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `block in require'
	from /var/lib/gems/1.9.1/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:214:in `load_dependency'
	from /var/lib/gems/1.9.1/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `require'
	from /var/lib/gems/1.9.1/gems/railties-4.0.5/lib/rails/engine.rb:591:in `block (2 levels) in <class:Engine>'
	from /var/lib/gems/1.9.1/gems/railties-4.0.5/lib/rails/engine.rb:590:in `each'
	from /var/lib/gems/1.9.1/gems/railties-4.0.5/lib/rails/engine.rb:590:in `block in <class:Engine>'
	from /var/lib/gems/1.9.1/gems/railties-4.0.5/lib/rails/initializable.rb:30:in `instance_exec'
	from /var/lib/gems/1.9.1/gems/railties-4.0.5/lib/rails/initializable.rb:30:in `run'
	from /var/lib/gems/1.9.1/gems/railties-4.0.5/lib/rails/initializable.rb:55:in `block in run_initializers'
	from /usr/lib/ruby/1.9.1/tsort.rb:150:in `block in tsort_each'
	from /usr/lib/ruby/1.9.1/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
	from /usr/lib/ruby/1.9.1/tsort.rb:210:in `block (2 levels) in each_strongly_connected_component_from'
	from /usr/lib/ruby/1.9.1/tsort.rb:219:in `each_strongly_connected_component_from'
	from /usr/lib/ruby/1.9.1/tsort.rb:209:in `block in each_strongly_connected_component_from'
	from /var/lib/gems/1.9.1/gems/railties-4.0.5/lib/rails/initializable.rb:FirstApp::Application.configure do
44:in `each'
	from /var/lib/gems/1.9.1/gems/railties-4.0.5/lib/rails/initializable.rb:44:in `tsort_each_child'
	from /usr/lib/ruby/1.9.1/tsort.rb:203:in `each_strongly_connected_component_from'
	from /usr/lib/ruby/1.9.1/tsort.rb:182:in `block in each_strongly_connected_component'
	from /usr/lib/ruby/1.9.1/tsort.rb:180:in `each'
	from /usr/lib/ruby/1.9.1/tsort.rb:180:in `each_strongly_connected_component'
	from /usr/lib/ruby/1.9.1/tsort.rb:148:in `tsort_each'
	from /var/lib/gems/1.9.1/gems/railties-4.0.5/lib/rails/initializable.rb:54:in `run_initializers'
	from /var/lib/gems/1.9.1/gems/railties-4.0.5/lib/rails/application.rb:215:in `initialize!'
	from /home/vagrant/first_app/config/environment.rb:5:in `<top (required)>'
	from /home/vagrant/first_app/config.ru:3:in `require'
	from /home/vagrant/first_app/config.ru:3:in `block in <main>'
	from /var/lib/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
	from /var/lib/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
	from /home/vagrant/first_app/config.ru:in `new'
	from /home/vagrant/first_app/config.ru:in `<main>'
	from /var/lib/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
	from /var/lib/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
	from /var/lib/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
	from /var/lib/gems/1.9.1/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
	from /var/lib/gems/1.9.1/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
	from /var/lib/gems/1.9.1/gems/railties-4.0.5/lib/rails/commands/server.rb:48:in `app'
	from /var/lib/gems/1.9.1/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
	from /var/lib/gems/1.9.1/gems/railties-4.0.5/lib/rails/commands/server.rb:75:in `start'
	from /var/lib/gems/1.9.1/gems/railties-4.0.5/lib/rails/commands.rb:76:in `block in <top (required)>'
	from /var/lib/gems/1.9.1/gems/railties-4.0.5/lib/rails/commands.rb:71:in `tap'
	from /var/lib/gems/1.9.1/gems/railties-4.0.5/lib/rails/commands.rb:71:in `<top (required)>'
	from bin/rails:8:in `require'
	from bin/rails:8:in `<main>'

対応

次のファイルの内容を変更する。
./config/environment/development.rb

Rails.application.configure do

を以下のように変更する。

Your_Rails_Application_Folder_name::Application.configure do

この際に「our_Rails_Application_Folder_name」は例えば「first_app」というプロジェクトであれば、「FirstApp」のように変更する。

例:「first_app」というアプリケーション名の場合

Rails.application.configure do

を次のように変更する。

FirstApp::Application.configure do

結果

railsによりサーバの起動が成功した。

vagrant@precise64:~/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
[2014-12-18 02:00:31] INFO  WEBrick 1.3.1
[2014-12-18 02:00:31] INFO  ruby 1.9.3 (2011-10-30) [x86_64-linux]
[2014-12-18 02:00:31] INFO  WEBrick::HTTPServer#start: pid=12060 port=3000

参照

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?