无法修改 'hello world' 应用程序的应用程序控制器
Can't modify Application Controller for 'hello world' app
我偶然发现了 Hartl 教程的第 1 章清单 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 < ActionController::Base
我明白了:
bash: ActionController::Base: No such file or directory
我做了什么:
我知道应用程序控制器存在,因为 $ ls app/controllers/*_controller.rb
returns 应用程序控制器文件。
我在控制器上发现的其他问题涉及 SecurityMethods 等主题,到目前为止我还没有看到它被提及。
我也试过只输入 class ApplicationController
并被告知 bash: class: command not found
。
问:在执行此步骤之前,我应该先 ActionController::Base
吗?
您是在控制台中输入 class ApplicationController < ActionController::Base
吗?
您应该做的是找到您的 sample_app/app/controllers/application_controller.rb 并在该文件中添加新文本。然后保存并关闭文件。
我偶然发现了 Hartl 教程的第 1 章清单 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 < ActionController::Base
我明白了:
bash: ActionController::Base: No such file or directory
我做了什么:
我知道应用程序控制器存在,因为 $ ls app/controllers/*_controller.rb
returns 应用程序控制器文件。
我在控制器上发现的其他问题涉及 SecurityMethods 等主题,到目前为止我还没有看到它被提及。
我也试过只输入 class ApplicationController
并被告知 bash: class: command not found
。
问:在执行此步骤之前,我应该先 ActionController::Base
吗?
您是在控制台中输入 class ApplicationController < ActionController::Base
吗?
您应该做的是找到您的 sample_app/app/controllers/application_controller.rb 并在该文件中添加新文本。然后保存并关闭文件。