1

I'm writing a rails application, and in this one controller I need to specify the layout to render due to inheriting from ActionController::Base. In some of my other controllers I just have ActionController and it automatically uses the application layout. Whenever I remove the ::Base, I get the following message when accessing the page superclass must be a Class (Module given).

Why does inheriting from ActionController::Base in this controller matter, but not in the others?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Kyle
  • 607
  • 2
  • 6
  • 14

2 Answers2

2

To directly answer your question ActionController is not a controller class, it's a namespacing module that powers the entire controller stack. You would not interact with the ActionController module during typical Rails development. ActionController::Base is actually the class that controllers inherit from. This is why you can't inherit from ActionController.

But I think there are two controllers in play here. ActionController::Base and ApplicationController. I think you might be mistaking ApplicationController for being ActionController without the ::Base.

ActionController::Base is the main controller class where all of your Rails functionality comes from. ApplicationController is a generalized controller that you can add methods to and have all of your other Rails controllers inherit from.

You could do the following to use a different layout in one of your controllers:

class AuthenticationController < ApplicationController
  layout 'authentication'
end

You can either use the AuthenticationController directly, or have new controllers inherit from AuthenticationController.

Joseph Ravenwolfe
  • 6,480
  • 6
  • 31
  • 31
0

Your controllers should inherit from ApplicationController. This will allow them to automatically render the application layout. ApplicationController extends ActionController::Base.

JohnColvin
  • 2,489
  • 1
  • 14
  • 8