简体   繁体   中英

uninitialized constant LoginController in Ruby.

I am newbie in Ruby. I installed by following this tutorial: http://udooz.net/blog/2011/02/facebook-app-using-rails-koala/

Now, when I do this: rails generate controller

rails generate controller home index

I get this error:

/home/hiccup-pro/Documents/qstack/config/environment.rb:8:in `<top (required)>': undefined local variable or method `config' for main:Object (NameError)
from /home/hiccup-pro/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.2.3/lib/rails/application.rb:103:in `require'
from /home/hiccup-pro/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.2.3/lib/rails/application.rb:103:in `require_environment!'
from /home/hiccup-pro/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.2.3/lib/rails/commands.rb:25:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

I fixed it. Atleast that bug, but now I've a different bug and that is: uninitialized constant LoginController. I googled a bit and found out that I should not mention config.* in the environment.rb. Anyway, this is my environment.rb

# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
Qack::Application.initialize!
config.action_controller.allow_forgery_protection = false

So, why do I get this uninitialized constant LoginController error?

Without seeing your environment.rb is hard to say, but my best shoot is that you put the code

config.action_controller.allow_forgery_protection = false
config.gem "koala"

Outside of the block

Rails::Initializer.run do |config|
  ....
end

That is inside of environment.rb. If there is no such a block add it like this:

Rails::Initializer.run do |config|
  config.action_controller.allow_forgery_protection = false
  config.gem "koala"
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM