Rails在多个标记过滤器上充当taggle [英] Rails acts as taggle on filter by multiple tags

查看:175
本文介绍了Rails在多个标记过滤器上充当taggle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



路线:
get'mainpage /:tag

我有一个模型Tasks,可以标记为gem上的taggable。 'to:'mainpage#index',如::tag



现在,当你点击一个标签时,它会带你进入带有该标签的所有任务。 / p>

我想要做的就是当你在一个标签页上时,点击一个额外的标签可以进一步过滤结果,点击标签名。 / p>

例子



标签账单(主页/账单)显示:

电缆(标有:电视,信用卡。票据)

椅子(标有:信用卡,账单)

b
$ b

表(标有:家具,钞票,沙拉)

当我点击信用卡标签页,我希望它只显示那些既是一个票据标签和信用卡标签的任务。



我有点盲目的如何这样做。



感谢任何帮助或建议

解决方案

http://guides.rubyonrails.org/routing.html 第3.11节:

  get' mainpage / * tags到:'mainpage#index',如::tag 

你有像 / mainpage / bills / mainpage / bills / tv / furniture 的网址。 b
$ b

第一个URL会在 mainpage#index 方法中加入 params [:tags] ==' ',而第二个会带有 params [:tags] =='bills / tv / furniture'。然后,您可以简单地在 / 上分隔 params [:tags]

请注意,出于seo的目的,您可能想要为URL提供一些术语,即标签在URL中总是按字母顺序排列。


I have a model, Tasks, that can be tagged with the acts as taggable on gem.

The route: get 'mainpage/:tag', to: 'mainpage#index', as: :tag

Right now, when you click on a tag, it brings you to all tasks with that tag.

What I'd like to do is make it so that once you're on a tag page, clicking an additional tag further filters the results with the clicked tag name.

Ex.

On page for tag bills (mainpage/bills) displays:

Cable (tagged with: tv, credit card. bills)

Chairs (tagged with: credit card, bills)

table (tagged with: furniture, bills, salad)

When I click on the 'credit card' tag while on the bills tag page, I'd like to have it display only those tasks which are both a bills tag AND and credit card tag.

I'm flying a bit blind as how to do this.

Thanks for any help or suggestions

解决方案

From http://guides.rubyonrails.org/routing.html section 3.11:

get 'mainpage/*tags, to: 'mainpage#index', as: :tag

Adding this route allows you to have URLs like /mainpage/bills and /mainpage/bills/tv/furniture.

The first URL would come into your mainpage#index method with params[:tags] == 'bills', while the second one would come in with params[:tags] == 'bills/tv/furniture'. You could then simply split params[:tags] on /.

Note, for seo purposes, you probably want to come up with some nomenclature for the URLs, i.e. the tags are always alphabetical in the URL or something like that.

这篇关于Rails在多个标记过滤器上充当taggle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆