ruby on rails - What is meant by 'Assignment Branch Condition Size too high' and how to fix it? -


in rails app, use rubocop check problems. today gave me error : assignment branch condition size show high. here's code :

def show   @category = category.friendly.find(params[:id])   @categories = category.all   @search = @category.products.approved.order(updated_at: :desc).ransack(params[:q])   @products = @search.result.page(params[:page]).per(50)   rate end 

what mean , how can fix it?

assignment branch condition (abc) size measurement of size of method. determined counting number of assignments, branches, , conditional statements. (more detail..)

to reduce abc size, move of assignments 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 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -