Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Can';t为'修改应用程序控制器;世界你好';应用程序_Ruby On Rails_Railstutorial.org - Fatal编程技术网

Ruby on rails Can';t为'修改应用程序控制器;世界你好';应用程序

Ruby on rails Can';t为'修改应用程序控制器;世界你好';应用程序,ruby-on-rails,railstutorial.org,Ruby On Rails,Railstutorial.org,我在CHP1中遇到了问题,Hartl的教程中列出了1.8 目标是将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:

我在CHP1中遇到了问题,Hartl的教程中列出了1.8

目标是将
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
相反,当我在第一行

class ApplicationController

我明白了:

bash:ActionController::Base:没有这样的文件或目录

我所做的:

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

我在控制器上发现的其他问题涉及到一些话题,比如安全方法,我到目前为止还没有提到过

我还尝试输入
类应用程序控制器
,结果被告知
bash:class:command未找到


问:在执行此步骤之前,我是否应该有一个
ActionController::Base


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

您只是在命令行中键入这个吗?@BradWerth是对的,您直接在命令行中键入(
bash
)。运行Rails控制台:
Rails控制台
(Rails>=3)或
脚本/控制台
(Rails<3)来运行命令。确定。所以我运行了
rails控制台
,命令行变成了这个
2.1.5:001>
。我输入了
'class ApplicationController
,结果是
=>“class ApplicationController
。不像预期的那样。尝试继续执行下一个命令
def hello
,结果导致出现混乱的
12.1.5:003?>
hello,world!谢谢大家。