开发者

Rails acts_as_taggable_on Tag Link Filtering

开发者 https://www.devze.com 2023-03-10 10:46 出处:网络
I have a list of \'notes\', and each note has some tags via acts_as_taggable_on. It\'s a great plugin, and the tags are working wonderfully.

I have a list of 'notes', and each note has some tags via acts_as_taggable_on. It's a great plugin, and the tags are working wonderfully.

What would be the best way to filter this list of notes by the tag that is clicked on?

Example:

<% @notes.each do |note| %>
  <%= note.c开发者_高级运维ontent %>

  <% note.tag_list.each do |tag| %>
    <%= link_to tag, '#', :class => "tag" %>
  <% end %>
<% end %>

What should I replace the '#' with in order to change or scope out @notes? Not too familiar with this.

EDIt: I want something just like StackOverFlow actually, how would I add parameters to the URL based on the link?

Thanks!


I believe I figured it out. Was just having an off-moment.

I can create a named route like:

match 'tags/:tag' => 'controller#index', :as => 'tag'

And that way I can get the parameter I need.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号