⟩ Explain me what is the difference between concern and application_controller.rb in ruby on rails?
Concerns are basically modules that get mixed into controller or model classes for instance. A Concern extends ActiveSupport::Concern module. It helps slim down the model/controller classes, and makes it easier to reuse common code across multiple model/controller classes. Concerns are like helper modules. We can define helper methods in concerns and can include or extend those concerns from various controller/model classes to sharing and DRY up the model/controller code.
On the other hand, ApplicationController is a controller class (NOT a module) and in your Rails application, it is the base class from which all of your other controllers classes are derived from. e.g.
class FooController < ApplicationController
. . .
end
class BarController < ApplicationController
. . .
end
In, Model–View–Controller (MVC) software architectural pattern, a controller implements business logics, can send commands to the model to update the model's state. It can also send commands to its associated view to change the view's presentation of the model. ApplicationController is that kind where as the Concerns are like helpers to get their job done.
Additional - Using concerns/services you can put your business logic in the controller; as a controller should not be business logic heavy, its main work is to get the request and get the response out.