Explain me what is the difference between concern and application_controller.rb in ruby on rails?
Submitted by: MuhammadConcerns 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.
Submitted by: Muhammad
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.
Submitted by: Muhammad
Read Online Ruby Developer Job Interview Questions And Answers
Top Ruby Developer Questions
☺ | Tell us what is class libraries in Ruby? |
☺ | Tell me can you call a private method outside a Ruby class using its object? |
☺ | Explain me what is the function of ORM in Ruby on Rails? |
☺ | Tell me the role of modules and mixins in Ruby? |
☺ | What is the difference extend and include? |
Top Web Developer Categories
☺ | Bootstrap Interview Questions. |
☺ | Front End Web Developer Interview Questions. |
☺ | Laravel PHP Developer Interview Questions. |
☺ | Typography Interview Questions. |
☺ | Junior Developer PHP Interview Questions. |