简体   繁体   English

合并搜索和筛选Rails 3和Meta_Search

[英]Merge Search and Filter Rails 3 and Meta_Search

I have this code: 我有以下代码:

    <div id="busca">
    <div id="form_busca">
        <%= form_for @search, :url => root_path, :html => {:method => :get} do |f| %>
            <%= f.text_field :bairro_or_cidade_or_logradouro_or_estado_contains ,:id => "campo_busca", :placeholder => "Pesquise por logradouro, bairro ou cidade" %>
            <%= f.submit "Buscar", :id => "btn_busca" %>            
    </div>
</div>
        <div id="filtros">
                <ul>
                    <li><%= link_to "Some Text", root_path(:search => {:quartos_less_than => 2}) %></li>
                    <li><%= link_to "Some Text2", params.merge(:search => {:quartos_less_than => 2}) %></li>
                    <li><%= link_to "1 quarto", root_path(params.merge(:search => params[:search], :filter => {:quartos_less_than => 2})) %></li>
                    <li><%= link_to "+ de 1 quarto", params.merge(:search => params[:search], :filter => {:quartos_greater_than => 2}) %></li>
                    <li><%= link_to "1 banheiro", params.merge(:search => params[:search], :filter => {:banheiros_less_than => 2}) %></li>
                    <li><%= link_to "+ de 1 banheiro", params.merge(:search => params[:search], :filter => {:banheiros_greater_than => 2}) %></li>
                </ul>
            </div>
        <a id="filtros_link" href="#">Filtros &raquo;</a>
<% end %>

I'd like to merge this links from filtros (filters) to a previous search. 我想将此链接从filtros (过滤器)合并到以前的搜索。 For exemple: I search for a city then I filter this search to show those that have 1 bathroom only. 例如:我搜索一个城市,然后过滤此搜索以显示仅具有1个浴室的城市。

Can someone helpe me? 有人可以帮我吗?

I'm using ruby 1.8.7 and Rails 3.0.4. 我正在使用ruby 1.8.7和Rails 3.0.4。 The search gem is meta_search. 搜索宝石是meta_search。

I thank you from now!! 我从现在开始谢谢你!

Well, the best way I got is to use different parameters instead of only :search. 好吧,我得到的最好方法是使用不同的参数而不是:search。 So, I'd use, for example, use the params :rooms :baths or any other not to merge, but to filter (let say this way). 因此,例如,我将使用params:rooms:baths或其他任何不合并但进行过滤的过滤器(这样说)。 The controller must be change as well. 控制器也必须更换。 Then, using :rooms and :baths params in view, controller should be something like this: 然后,在视图中使用:rooms和:baths参数,控制器应如下所示:

@search = Property.search(params[:search][:rooms][:baths])

Didn't test this! 没有测试!

I've change this to checks which meta_search has helpers for this. 我将其更改为检查哪个meta_search具有此帮助器。

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

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