无法修改“hello world”应用程序的应用程序控制器

时间:2015-04-27 23:52:14

标签: ruby-on-rails railstutorial.org

我偶然发现了Hartl教程1.8的Chp 1。

目标是将hello操作放入应用程序控制器。

这应该发生:

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception`

  def hello
    render text: "hello, world!"
  end
end

相反,当我放入第一行

class ApplicationController < ActionController::Base

我明白了:

bash: ActionController::Base: No such file or directory

我做了什么:

我知道Application控制器存在,因为$ ls app/controllers/*_controller.rb返回Application控制器文件。

我在控制器上发现的其他问题涉及到目前为止我还没有提到的SecurityMethods等主题。

我还尝试输入class ApplicationController,并被告知bash: class: command not found

问:在采取这一步骤之前,我应该有ActionController::Base吗?

1 个答案:

答案 0 :(得分:2)

您是否在控制台中输入了class ApplicationController < ActionController::Base

您应该做的是找到 sample_app / app / controllers / application_controller.rb 并在该文件中添加新文本。然后保存并关闭该文件。