如何重写此代码,使其完全动态,并且我不必使用该case
子句手动列出 的所有可能值@group
?
# Grouping
@group = params[:group] if !params[:group].blank?
case @group
when 'category_id'
@ideas_grouped = @ideas.group_by { |i| i.category_id }
when 'status_id'
@ideas_grouped = @ideas.group_by { |i| i.status_id }
when 'personal_bias'
@ideas_grouped = @ideas.group_by { |i| i.personal_bias }
when 'business_value'
@ideas_grouped = @ideas.group_by { |i| i.business_value }
end