1
class Admin::ApplicationController < ApplicationController
  def index
  end
end

Which class get inherited when I using nested class?

class Admin < ApplicationController
  class ApplicationController
  end
end

or

class Admin 
  class ApplicationController < ApplicationController
  end
end

I think the second one is the winner, because what I understand Admin::ApplicationController < ApplicationController is get the ApplicationController inside Admin namespace and make it inherit from ApplicationController.

XY L
  • 25,431
  • 14
  • 84
  • 143

1 Answers1

1

If the question is what is the equivalent of this line:

class Admin::ApplicationController < ApplicationController

Then your second assumption is correct, it is equivalent to:

class Admin 
  class ApplicationController < ApplicationController
  end
end

Few sidenotes though:

  1. Your current design exposes bad naming
  2. Why not make Admin a module instead of class?
  3. Prefer using the explicit form instead of nested one - you'll never get confused.
  4. See this thread about some difference in levels of nesting between two forms of class definitions.
Community
  • 1
  • 1
Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145
  • Thanks, Andrey. I am new to Rails. I am reading Rails in Action 4. The first code block is the sample code from the book. The reason I ask this question is because Rubocop tell me not use compact format. – XY L Oct 17 '16 at 07:22
  • 1
    @LiXinyang I somehow missed your comment. I believe Rubocop's warnings are worth of listening. Good that you're using it (I do, too) – Andrey Deineko Oct 17 '16 at 17:11