반응형
'할당 분기 조건 크기가 너무 큼'은 무엇을 의미하며 어떻게 해결합니까?
내 Rails 앱에서 Rubocop
문제를 확인 하는 데 사용 합니다. 오늘은 다음과 같은 오류가 발생했습니다 Assignment Branch Condition size for show is too high
. 내 코드는 다음과 같습니다.
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
이것이 의미하는 바는 무엇이며 어떻게 해결할 수 있습니까?
ABC (Assignment Branch Condition) 크기는 분석법의 크기를 측정 한 것입니다. 본질적으로 A ssignments, B ranches 및 C onditional 진술 의 수를 세어 결정됩니다 . (자세한 세부 사항..)
ABC 점수를 줄이기 위해 이러한 할당 중 일부를 before_action 호출로 이동할 수 있습니다.
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
반응형
'program story' 카테고리의 다른 글
어떤 Java FTP 클라이언트 라이브러리를 사용해야합니까? (0) | 2020.09.06 |
---|---|
일하는 사람을위한 결합 자 설명 (0) | 2020.09.06 |
JavaScript에서 UUID를 생성 할 때 충돌이 발생합니까? (0) | 2020.09.06 |
교리 수화 란 무엇입니까? (0) | 2020.09.06 |
T-SQL : UPDATE 문에서 CASE를 사용하여 조건에 따라 특정 열 업데이트 (0) | 2020.09.05 |