Can't modify Application Controller for 'hello world' app

亡梦爱人 提交于 2019-12-24 22:29:28

问题


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

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

This is supposed to happen:

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 < ActionController::Base

I get this:

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

What I've done:

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

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

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

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


回答1:


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

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.



来源:https://stackoverflow.com/questions/29907915/cant-modify-application-controller-for-hello-world-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!