Search code examples
ruby-on-railsrailstutorial.org

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


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?


Solution

  • 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.