2016-03-08 125 views
0

我想搜索的點擊搜索這兩個類別和地點有多個選項(搜查)如何搜索上的點擊通過搜查搜索提交

我看來

<%= form_tag location_path, :method=>'get' do %> 
<%= select_tag :q, options_from_collection_for_select(Category.all, :id, :name, params[:q]) %> 
<%= text_field_tag :q, nil,:placeholder=>"Tell us what you are looking for.." %> 
<input type="submit" value="SEARCH" class="btn1 home-search-button" > 
<% end %> 

這是我的看法這種形式 enter image description here 我searchcontroller是

def location 
    q = params[:q] 
    @key=q 
    @property = Property.ransack(location_or_category_name_cont: q).result(distinct: true) 
    end 

this search searches only location not category, 
on executing i am getting like this, 
`url is like this : http://localhost:3000/location?utf8=%E2%9C%93&q=2&q=banglore` 

命令IAM讓上執行 enter image description here` 這是搜索班加羅爾的類別名稱及位置(應該搜索「商業」爲CATEGORY_NAME(這是在CATEGORY_ID:2)instaed班加羅爾」的

任何幫助是appreciatable

現在我得到這樣,SEACH查詢是錯誤的 `enter image description here

回答

1
<%= form_tag location_path, :method=>'get' do %> 
<%= select_tag :category_id, options_from_collection_for_select(Category.all, :id, :name, params[:q]) %> 
<%= text_field_tag :q, nil,:placeholder=>"Tell us what you are looking for.." %> 
<input type="submit" value="SEARCH" class="btn1 home-search-button" > 
<% end %> 

試試這個

您正在使用相同的參數名稱的位置爲w至於類別,並且正在被覆蓋。

+0

當我試圖這樣 – SreRoR

+0

是它的工作? –

+0

沒有一些查詢錯誤。我更新了我上面的終端屏幕截圖。請檢查 – SreRoR

0

不確定您使用的是什麼版本的ransack,但根據文檔ransack,下面的問題將解決該問題。

在你看來,應該使用search_form_for幫手

<%= search_form_for @q do |f| %> 
    <%= f.label :category_name_cont %> 
    <%= f.select :category_name_cont, options_from_collection_for_select(Category.all, "name", "name", @q.category_name_cont) %> 

    <%= f.label :location_name_cont %> 
    <%= f.search_field :location_name_cont %> 

    <%= f.submit %> 

<% end %> 

,並在控制器

def location 
    @q = Property.ransack(params[:q]).result(distinct: true) 
end