Created
June 7, 2011 23:33
-
-
Save ShepFc3/1013446 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@user_groups = {} | |
if params[:filter] && params[:filter][:dynamic] | |
group_ids = feed_search.dynamic_usertags.collect { |e| e.gsub('group_id:','') } | |
group_ids.each do |group_id| | |
group = Group.find group_id | |
@user_groups[group.primary_filter.name.downcase] = group if group | |
end | |
end | |
# Refactor | |
@user_groups = {} | |
if params[:filter] && params[:filter][:dynamic] | |
primary_filter_groups = current_user.groups.with_primary_filter | |
params[:filter][:dynamic].each do |dyn| | |
group = primary_filter_groups.select{ |g| g.primary_filter.filter_type == dyn } | |
@user_groups[group.primary_filter.filter_type] = group if group | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's my final refactor. Moved the query by filter type to a named scope.
if params[:filter] && params[:filter][:dynamic]
@user_groups = Hash[*current_user.groups.with_primary_filter.by_filter_type(
params[:filter][:dynamic]
).collect{ |group|
[group.primary_filter.filter_type, group]
}.compact.flatten]
end