Concerns to the Rescue.

  • Concerns are helpers that are used  to slim down the codes in models
    and the controllers.
  • Primary logic to implement are fatty models and skinny controllers.
  • According to the rubocop guidelines, the possible LOC allowed in a file is 100 to 120 in a file.
  • we can create model concerns, controller concerns.
  • in order to use that, we need to add the folders to application.rb saying that these folders are selected for the code execution.
  • need to create a folder inside the models folder called concerns
  • Suppose we have a specific Requirement to handle and we do not want trouble this code with existing work flow, then we can use concerns are in place.

1.create folders called concerns:

Need to create the folders in app/models as well as the app/controllers

2.Add path to Application.rb

need to add the folder path to  application.rb to include these files are needed.

3.png

3. save the file inside the concerns directory:

create a file called concern_test.rb in to app/models/concerns/

module ConcernTest

extend ActiveSupport::Concern

included do

    #here we can include class methods as well as the instance methods.

end

 

Thats it .Now your code works like charm. If you are using sublime, It has auto typing features will do the rest of the codes entering.

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s