11

I'm following this post for integrating Omniauth Twitter + Devise http://sourcey.com/rails-4-omniauth-using-devise-with-twitter-facebook-and-linkedin/ and I have encounter an issue that is blocking me to start my rails app.

 /Users/javier/Desktop/definitive/config/environment.rb:8:in `<top (required)>': undefined     local variable or method `config' for main:Object (NameError)
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
from /Users/javier/Desktop/definitive/config.ru:3:in `block in <main>'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
from /Users/javier/Desktop/definitive/config.ru:in `new'
from /Users/javier/Desktop/definitive/config.ru:in `<main>'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/server.rb:50:in `app'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/server.rb:130:in `log_to_stdout'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/server.rb:67:in `start'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:81:in `block in server'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:76:in `tap'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:76:in `server'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/javier/Desktop/definitive/bin/rails:8:in `require'
from /Users/javier/Desktop/definitive/bin/rails:8:in `<top (required)>'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `load'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `call'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
from /Users/javier/Desktop/definitive/bin/spring:16:in `require'
from /Users/javier/Desktop/definitive/bin/spring:16:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'

I guess the issue is in the line 8 of config/environment.rb but can not find with the right fix. Is it possible that environment.rb should be included in 'config/environments/'?

malditojavi
  • 1,074
  • 2
  • 14
  • 28

3 Answers3

16

The article states that you should put some code in:

config/environments/[environment].rb

Where [environment].rb is meant to signify one of the following files:

config/environments/development.rb
config/environments/production.rb
config/environments/test.rb

You could also put the code in config/application.rb if you want the same settings across your different environments.

The lines of code shown start with config.*, and they should be placed inside the Rails.application.configure do block.

config/environment.rb in a typical Rails 4 application is just a require and Rails.application.initialize!, and should not need modification.

Unixmonkey
  • 18,485
  • 7
  • 55
  • 78
  • Included in 'config/environments/development.rb' but it returns me an issue in the 13 line that is 'authentication => :plain' Log is: 'Users/javier/Desktop/definitive/config/environments/development.rb:13:in `block in ': undefined local variable or method `authentication' for # (NameError)' – malditojavi Jun 17 '14 at 21:05
  • Also tried adding it to the 'application.rb' Didn't know that 'environment.rb' usually remains un-edited, thanks for pointing it out. – malditojavi Jun 17 '14 at 21:09
  • Ah, looks like there's also a typo in the blog post. `authentication => :plain,` should be `authentication: :plain` – Unixmonkey Jun 17 '14 at 21:20
  • It keeps returning the issue. I have uploaded the gist with the issues and the github of the app is this one https://gist.github.com/malditojavi/d68121b21ed861cab830 https://github.com/malditojavi/definitive/blob/master/config/environments/development.rb – malditojavi Jun 17 '14 at 21:32
  • Same typo, next line (14): `domain => 'somedomain.com'` should be `domain: 'somedomain.com'`. Hash keys cannot be barewords when using the hashrocket. – Unixmonkey Jun 17 '14 at 21:40
  • This issue is now solved, restarted also the terminal. Thanks a lot for your help. – malditojavi Jun 17 '14 at 21:56
3

If you have config.xxx in environment.rb

delete it and add these into development.rb:

Rails.application.configure do
  config.xxx
end
Jerry Z.
  • 2,031
  • 3
  • 22
  • 28
0

I have also faced such an error(

NameError: undefined local variable or method `server' for main:Object
        from (irb):1
        from C:/RailsInstaller/Ruby2.2.0/bin/irb:11:in `<main>'),

)

maybe its because I am a Newbie in ruby on rails. hence instead of starting the rails server from direct command line I tried it to start from inside of IRB hence I got that error.

when I came out of IRB and started the server again from CMD it started smoothly.

Amol Patil
  • 238
  • 1
  • 2
  • 7