无法修改“hello world"应用程序的应用程序控制器 [英] Can't modify Application Controller for 'hello world' app

查看:38
本文介绍了无法修改“hello world"应用程序的应用程序控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶然发现了 Hartl 教程的第 1 章,清单 1.8.

I've stumbled at Chp 1, Listing 1.8 of Hartl's tutorial.

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

The goal is to place a hello action into the Application controller.

这是应该发生的:

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

相反,当我放入第一行时

Instead, when I put in the first line

class ApplicationController

我明白了:

bash: ActionController::Base: 没有那个文件或目录

我所做的:

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

I know the Application controller exists because $ ls app/controllers/*_controller.rb returns the Application controller file.

我在控制器上发现的其他问题涉及诸如 SecurityMethods 之类的主题,但我目前还没有看到这些主题.

Other questions I've found on controllers concern topics such as SecurityMethods which I haven't seen mentioned so far.

我也尝试只输入 class ApplicationController 并被告知 bash: class: command not found.

I also tried just inputting class ApplicationController and was told bash: class: command not found.

问:在执行这一步之前,我应该有一个 ActionController::Base 吗?

Q: Am I supposed to have an ActionController::Base before taking this step?

推荐答案

您是否正在键入 class ApplicationController <;ActionController::Base 进入控制台?

Are you typing class ApplicationController < ActionController::Base into the console?

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

What you are supposed to do is find your sample_app/app/controllers/application_controller.rb and add the new text inside that file. Then save and close the file.

这篇关于无法修改“hello world"应用程序的应用程序控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆