2016-08-15 56 views
0

我有一个表称为key_words至极已一列称为name与搜查trought阵列搜索表

然后,我有另一个表称为publications与被叫key_words至极它是array类型的柱。

当我创建发布保存在key_words值是这样的["1", "29", "40"](这些是保存在key_words表IDS)

我如何才能找到一个发布,如果我在搜索input

类型。例如 computers

在这一刻我有一个search_form_for由出版物找到titledescription

= search_form_for @search, url: publications_path do |f| 
    #custom-search-input 
    .input-group.col-md-12 
     = f.input :title_or_short_description_or_description_cont, input_html: { class: 'form-control input-sm' }, placeholder: 'Buscar', label: false 

感谢您的帮助

回答

0

我会创建第三个表key_words_publications来存储关系而不是数组列。查看HABTM here的文档。

class Publication 
    has_and_belongs_to_many :key_words 
end 

class KeyWord 
    has_and_belongs_to_many :publications 
end 

那么你应该能够做这样的事情: key_words_name_cont