07-19-2023, 12:54 AM
Working on an initial Rails project, and using [Rubocop](
# app/models/app_core/tenant.rb
module AppCore
class Tenant < ActiveRecord::Base
end
end
and a controller:
# app/controllers/app_core/tenant/members_controller.rb
module AppCore
class Tenant::MembersController < ApplicationController
end
end
In the model's case, the module is the same as the path and the class name is the same as the file name. In the controllers case, the second part of the path, "tenant" is part of the class name.
Rubocop tells me that I should "Use nested class definitions instead of compact style" in the `Tenant::MembersController` line, so if I understand correctly...
module AppCore
class Tenant
class MembersController < ApplicationController
end
end
end
...this shouldn't make a difference.
Now, my question is I have AppCore::Tenant as a model, but then AppCore::Tenant looks to be reopened and the MembersController class is added to it as a nested class. Does this mean that my Tenant class will always have that nested class in it? Do I need to name my models and controller routes something differently? Is this totally fine and nothing to worry about? Not exactly sure what this means.
[To see links please register here]
) to analyze code style. It led me to question exactly how Ruby's nested classes work in the context of Rails. For example, in my engine, I have a model:# app/models/app_core/tenant.rb
module AppCore
class Tenant < ActiveRecord::Base
end
end
and a controller:
# app/controllers/app_core/tenant/members_controller.rb
module AppCore
class Tenant::MembersController < ApplicationController
end
end
In the model's case, the module is the same as the path and the class name is the same as the file name. In the controllers case, the second part of the path, "tenant" is part of the class name.
Rubocop tells me that I should "Use nested class definitions instead of compact style" in the `Tenant::MembersController` line, so if I understand correctly...
module AppCore
class Tenant
class MembersController < ApplicationController
end
end
end
...this shouldn't make a difference.
Now, my question is I have AppCore::Tenant as a model, but then AppCore::Tenant looks to be reopened and the MembersController class is added to it as a nested class. Does this mean that my Tenant class will always have that nested class in it? Do I need to name my models and controller routes something differently? Is this totally fine and nothing to worry about? Not exactly sure what this means.