简体   繁体   English

Ruby中未初始化的常量LoginController。

[英]uninitialized constant LoginController in Ruby.

I am newbie in Ruby. 我是Ruby的新手。 I installed by following this tutorial: http://udooz.net/blog/2011/02/facebook-app-using-rails-koala/ 我是按照以下教程安装的: http://udooz.net/blog/2011/02/facebook-app-using-rails-koala/ : http://udooz.net/blog/2011/02/facebook-app-using-rails-koala/

Now, when I do this: rails generate controller 现在,当我这样做时:rails generate controller

rails generate controller home index Rails生成控制器主目录

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. 最了解该错误,但现在我遇到了另一个错误,那就是:未初始化的常量LoginController。 I googled a bit and found out that I should not mention config.* in the environment.rb. 我在Google上搜索了一下,发现我不应该在environment.rb中提到config。*。 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? 那么,为什么我会得到这个uninitialized constant LoginController错误?

Without seeing your environment.rb is hard to say, but my best shoot is that you put the code 没有看到您的environment.rb很难说,但是我的最佳选择是您放置了代码

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. 那是在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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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