Skip to content

Instantly share code, notes, and snippets.

@garrettlancaster
Last active December 22, 2015 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garrettlancaster/6529990 to your computer and use it in GitHub Desktop.
Save garrettlancaster/6529990 to your computer and use it in GitHub Desktop.
resources :submissions do
get 'tagged(/*tags)', to: 'submissions#index', on: :collection, :filters => /.+?/, as: :tagged
end
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