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/'?
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.
If you have config.xxx in environment.rb
delete it and add these into development.rb:
Rails.application.configure do
config.xxx
end
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.
Related
I've just woken up and can't start the rails server using rails s. I get the following error:
$ rails s
c:/Sites/wtna/config/application.rb:9:in `<top (required)>': undefined local variable or method `config' for main:Object (NameError)
from C:/RailsInstaller/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:133:in `require'
from C:/RailsInstaller/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:133:in `block in perform'
from C:/RailsInstaller/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:130:in `tap'
from C:/RailsInstaller/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:130:in `perform'
from C:/RailsInstaller/Ruby22-x64/lib/ruby/gems/2.2.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
from C:/RailsInstaller/Ruby22-x64/lib/ruby/gems/2.2.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
from C:/RailsInstaller/Ruby22-x64/lib/ruby/gems/2.2.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
from C:/RailsInstaller/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.1.6/lib/rails/command/base.rb:63:in `perform'
from C:/RailsInstaller/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.1.6/lib/rails/command.rb:44:in `invoke'
from C:/RailsInstaller/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.1.6/lib/rails/commands.rb:16:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
All was running fine 10 hours ago. Any suggestions?
It turns out that commenting out the following line in config/application.rb (which I took from dotdotdotPaul: How can I completely disable CoffeeScript in a Rails 3.1 app?) cured the problem:
config.generators.javascript_engine :js
I'm working on a application in Ruby on Rails, and I changed my version of Rails and Rake. rails server does not work anymore:
~/sample_app/config.ru:4:in `block in <main>': uninitialized constant SampleApp (NameError)
from /var/lib/gems/1.9.1/gems/rack-1.2.8/lib/rack/builder.rb:46:in `instance_eval'
from /var/lib/gems/1.9.1/gems/rack-1.2.8/lib/rack/builder.rb:46:in `initialize'
from /home/sara/Documents/M1/s8/web avancé/projet/sample_app/config.ru:1:in `new'
from /home/sara/Documents/M1/s8/web avancé/projet/sample_app/config.ru:1:in `<main>'
from /var/lib/gems/1.9.1/gems/rack-1.2.8/lib/rack/builder.rb:35:in `eval'
from /var/lib/gems/1.9.1/gems/rack-1.2.8/lib/rack/builder.rb:35:in `parse_file'
from /var/lib/gems/1.9.1/gems/rack-1.2.8/lib/rack/server.rb:162:in `app'
from /var/lib/gems/1.9.1/gems/rack-1.2.8/lib/rack/server.rb:253:in `wrapped_app'
from /var/lib/gems/1.9.1/gems/rack-1.2.8/lib/rack/server.rb:204:in `start'
from /var/lib/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands/server.rb:65:in `start'
from /var/lib/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:30:in `block in <top (required)>'
from /var/lib/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:27:in `tap'
from /var/lib/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Make sure you run bundle again to update to the newer versions of rails and rake.
I keep getting this error since updating to rails 4.1.1 and starting my console in production as: RAILS_ENV=production rails c
load error: /home/tristan/.rvm/rubies/ruby-2.1.1/.irbrc
NoMethodError: undefined method `split' for nil:NilClass
/home/tristan/.rvm/scripts/irbrc.rb:41:in `<top (required)>'
/home/tristan/joggle/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
/home/tristan/joggle/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `block in require'
/home/tristan/joggle/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
/home/tristan/joggle/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
/home/tristan/.rvm/rubies/ruby-2.1.1/.irbrc:11:in `<top (required)>'
/home/tristan/joggle/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load'
/home/tristan/joggle/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `block in load'
/home/tristan/joggle/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
/home/tristan/joggle/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load'
/home/tristan/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/irb/init.rb:236:in `run_config'
/home/tristan/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/irb/init.rb:19:in `setup'
/home/tristan/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/irb.rb:380:in `start'
/home/tristan/joggle/shared/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/commands/console.rb:90:in `start'
/home/tristan/joggle/shared/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/commands/console.rb:9:in `start'
/home/tristan/joggle/shared/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:69:in `console'
/home/tristan/joggle/shared/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
/home/tristan/joggle/shared/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
I just had this same issue. I ran 'spring stop' then 'rails c' and it corrected the error. Something got mucked up with the environment because line 41 of that irbrc.rb file refers to the ENV variable GEM_HOME, which I confirmed was actually set.
Does that fix your issue?
I tried upgrading from Rails 3.0.23 to 3.2.13 and now I have an error stopping the server from starting that looks like this:
/Users/hamiltonchapman/Projects/project-static/lib/markdown_handler.rb:3:in `<top (required)>': uninitialized constant ActionView::Template::Handler (NameError)
from /Users/hamiltonchapman/Projects/project-static/config/environment.rb:9:in `<top (required)>'
from /Users/hamiltonchapman/Projects/project-static/config.ru:5:in `require'
from /Users/hamiltonchapman/Projects/project-static/config.ru:5:in `block in <main>'
from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
from /Users/hamiltonchapman/Projects/project-static/config.ru:in `new'
from /Users/hamiltonchapman/Projects/project-static/config.ru:in `<main>'
from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'
from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/railties-3.2.13/lib/rails/commands/server.rb:46:in `app'
from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'
from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/railties-3.2.13/lib/rails/commands/server.rb:70:in `start'
from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/railties-3.2.13/lib/rails/commands.rb:55:in `block in <top (required)>'
from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:9:in `require'
from script/rails:9:in `<main>'
The code that is causing this looks like:
require 'kramdown'
class MarkdownHandler < ActionView::Template::Handler
def self.call(template)
new.render(template, nil)
end
def render(template, local_assigns)
%(Kramdown::Document.new(
ERB.new(#{template.source.inspect}).result(binding)
).to_html.html_safe)
end
end
ActionView::Template.register_template_handler :emd, MarkdownHandler
ActionView::Template.register_template_handler :md, MarkdownHandler
However, if I just remove the inheritance then the server starts fine and all of the markdown files render as expected.
Any ideas as to what's going wrong?
I am trying to disable the parts of rails that i'm not using in my application, such as ActionMailer. Ib my application.rb, I made the following change
require "action_controller/railtie"
require "action_mailer/railtie"
#require 'rails/all'
And my app works fine. Now when I go and comment out the 'require "action_mailer/railtie"' line, I get the following error. I don't haveany mailers installed, so what's going on?
Thanks
=> Booting WEBrick
=> Rails 3.0.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/railtie/configuration.rb:77:in `method_missing': undefined method `action_mailer' for #<Rails::Application::Configuration:0x00000002c337f8> (NoMethodError)
from /home/test/shipped/deluxe/deluxe/config/environments/development.rb:18:in `block in <top (required)>'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/application.rb:47:in `class_eval'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/application.rb:47:in `configure'
from /home/test/shipped/deluxe/deluxe/config/environments/development.rb:1:in `<top (required)>'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `block in require'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `block in load_dependency'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/application/bootstrap.rb:11:in `block in <module:Bootstrap>'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `instance_exec'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `run'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/initializable.rb:50:in `block in run_initializers'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `each'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `run_initializers'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/application.rb:134:in `initialize!'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/application.rb:77:in `method_missing'
from /home/test/shipped/deluxe/deluxe/config/environment.rb:6:in `<top (required)>'
from /home/test/shipped/deluxe/deluxe/config.ru:3:in `require'
from /home/test/shipped/deluxe/deluxe/config.ru:3:in `block in <main>'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/builder.rb:46:in `instance_eval'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/builder.rb:46:in `initialize'
from /home/test/shipped/deluxe/deluxe/config.ru:1:in `new'
from /home/test/shipped/deluxe/deluxe/config.ru:1:in `<main>'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/builder.rb:35:in `eval'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/builder.rb:35:in `parse_file'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/server.rb:162:in `app'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/server.rb:248:in `wrapped_app'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/server.rb:213:in `start'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/commands/server.rb:65:in `start'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/commands.rb:30:in `block in <top (required)>'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap'
from /home/test/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Be careful, config.frameworks is deprecated in Rails 3!
The error you've got is coming from the #18 line of the file development.rb :
config.action_mailer.raise_delivery_errors = false
Since you do not require it anymore, config.action_mailer is undefined. You just have to comment the line and you will be fine.
In application.rb
config.frameworks -= [:action_mailer]