Assignment Branch Condition (ABC) size is a measurement of the size of a method. It is essentially determined by counting the number of Assignments, Branches, and Conditional statements. (more detail..)
To reduce ABC score, you could move some of those assignments into before_action calls:
before_action :fetch_current_category, only: [:show,:edit,:update]
before_action :fetch_categories, only: [:show,:edit,:update]
before_action :fetch_search_results, only: [:show,:edit,:update] #or whatever
def show
rate
end
private
def fetch_current_category
@category = Category.friendly.find(params[:id])
end
def fetch_categories
@categories = Category.all
end
def fetch_search_results
@search = category.products.approved.order(updated_at: :desc).ransack(params[:q])
@products = @search.result.page(params[:page]).per(50)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With