Last active
December 22, 2015 20:59
-
-
Save garrettlancaster/6529990 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
- submission_tag_types.each do |type| | |
%li.nav-header= type.humanize | |
- Submission.tag_options_for(type).each do |tag| | |
= link_to_tag(tag) |
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
resources :submissions do | |
get 'tagged(/*tags)', to: 'submissions#index', on: :collection, :filters => /.+?/, as: :tagged | |
end |
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
class SubmissionsController | |
... | |
helper_method :tag_set | |
def tag_set | |
@tag_set ||= Set.new Array(params[:tags].to_s.split('/')) | |
end | |
end | |
class Submission | |
def self.tag_options_for(type) | |
tags_on(type).order("LOWER(name)").pluck(:name) | |
end | |
end | |
module SubmissionsHelper | |
def submission_tag_types | |
%w(languages frameworks tags) | |
end | |
def link_to_tag(tag) | |
active = tag_set.include?(tag) | |
tags = (tag_set ^ Set.new([tag])).to_a | |
content_tag(:li, class: active ? 'active' : '') do | |
link_to tag, tagged_submissions_path(tags: tags) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment