2015-04-27 86 views
0

我已经偶然发现了Hartl教程的第1章清单1.8。无法修改'hello world'应用程序的应用程序控制器

目标是将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

什么我没有e:

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

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

我也试过只是输入class ApplicationController,被告知bash: class: command not found

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

+1

你只是在命令行输入这个? –

+0

@BradWerth是对的,你直接在命令行输入('bash')。运行Rails控制台:'rails console'(rails> = 3)或'script/console'(rails <3)来运行你的命令。 – pierallard

+0

好的。所以我运行了'rails console',命令行变成了这个'2.1.5:001>'。我输入''ApplicationController “类ApplicationController ' –

回答

2

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

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

+0

hello,world!谢谢大家。 –

相关问题