Makes tag checking more efficient in Debates#index

1) Only loads the tags if params[:tag] is present
2) Only checks for existence of the tag, instead of loading them all
and getting their names
This commit is contained in:
kikito
2015-09-03 11:18:39 +02:00
parent e0f8f8d8de
commit 3f98ab74b0

View File

@@ -85,8 +85,9 @@ class DebatesController < ApplicationController
end
def parse_tag_filter
valid_tags = ActsAsTaggableOn::Tag.all.map(&:name)
@tag_filter = params[:tag] if valid_tags.include?(params[:tag])
if params[:tag].present?
@tag_filter = params[:tag] if ActsAsTaggableOn::Tag.where(name: params[:tag]).exists?
end
end
end