简体   繁体   English

Ruby on Rails-搜索虚拟属性(标签)

[英]Ruby on Rails - Searching virtual attributes (tags)

I've set up a Virtual Attribute tagging system as shown by Ryan Bates here: http://railscasts.com/episodes/167-more-on-virtual-attributes 我已经建立了一个虚拟属性标记系统,如Ryan Bates所示: http : //railscasts.com/episodes/167-more-on-virtual-attributes

The system works really well for applying tags to my models and is something I implemented into my system a couple of days ago. 该系统对于将标签应用于模型非常有效,这是几天前我在系统中实现的。 I then went in and followed the simple search tutorial by Ryan Bates here: http://railscasts.com/episodes/37-simple-search-form . 然后,我进入并遵循Ryan Bates的简单搜索教程,网址为: http : //railscasts.com/episodes/37-simple-search-form My issue is that now my search form searches though names and I just happen to have implemented tags - it only makes sense for me to also be searching the tags. 我的问题是,现在我的搜索表单通过名称进行搜索,而我恰好实现了标签-对我来说搜索标签也是很有意义的。 Unfortunately I'm not extremely experienced in Ruby on Rails and the only way I could even get it to kind of work was to do a bunch of loops that looped around everything and even then I couldn't figure out how to search the array I'd got (and the loops made everything very sluggish). 不幸的是,我对Ruby on Rails的经验不是很丰富,我什至可以将其用于某种工作的唯一方法是进行一堆循环遍历所有事物的循环,即使这样我也无法弄清楚如何搜索数组得了(循环使一切都很缓慢)。

Does anyone know how I could do something like this? 有人知道我该怎么做吗?

I ended up using Sunspot as shown here: http://railscasts.com/episodes/278-search-with-sunspot 我最终使用了Sunspot,如下所示: http : //railscasts.com/episodes/278-search-with-sunspot

With code as shown here: 带有如下所示的代码:

text :taggings do
        taggings.map{ |tagging| tagging.tag.name }
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM