Rails无法看到我的控制器

时间:2011-10-02 00:39:50

标签: ruby-on-rails-3 controller

鉴于:

/app/controllers下的两个控制器名为:

  • customers_controller.rb(CustomersController)
  • home_controller.rb(HomeController)

问题:

当我运行rails命令(即rails c)时,这就是我得到的:

ruby-1.9.2-p290 :001 > CustomersController
 => CustomersController 
ruby-1.9.2-p290 :002 > HomeController
NameError: uninitialized constant HomeController
    from /home/aaron/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.8.7/lib/rake.rb:2503:in `const_missing'
    from (irb):2
    from /home/aaron/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.9/lib/rails/commands/console.rb:44:in `start'
    from /home/aaron/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.9/lib/rails/commands/console.rb:8:in `start'
    from /home/aaron/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.9/lib/rails/commands.rb:23:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

那么这笔交易是什么?为什么我的应用程序无法识别HomeController

修改

我的home_controller.rb文件:

class HomeController < ApplicationController
  def index
  end

  def sign_up
  end

  def faq
  end

  def terms
  end

  def privacy
  end

  def feedback
  end

end

Theres并不多。

1 个答案:

答案 0 :(得分:1)

适用于Rails 3.0.7 ...您使用的是哪个版本的Rails?

在较新的Rails版本中,旧版本的Rake存在问题,我注意到你使用的是旧版本的Rake ..

尝试将其放入Gemfile:

gem 'rake' , '>= 0.9.1'

然后进行“捆绑更新”

并再次尝试“rails c”..

之后它对你有用吗?

另见:

Confused with rake error in Rails 3

相关问题