开发者

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. For exemple: I search for a city then I filter this search to show those that have 1 bathroom only.

Can someone helpe me?

I'm using ruby 1.8.7 and Rails 3.0.4. The search gem is meta_search.

I thank you from now!!


Well, the best way I got is to use different parameters instead of only :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). The controller must be change as well. Then, using :rooms and :baths params in view, controller should be something like this:

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

Didn't test this!

I've change this to checks which meta_search has helpers for this.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜