2014-01-18 51 views
3

我正在使用Rails 3.2,我已經安裝了Ransack搜索和Kaminari分頁。這兩塊寶石的工作絕對平穩。Rails的搜索和重定向到另一個頁面

我很好奇如何在主頁上進行搜索,並在用戶輸入搜索輸入後,將他重定向到其中列出所有結果的另一個頁面。

類似的東西來Zomato搜索

截至目前,這是控制器代碼:

def index 
    @search = Product.search(params[:q]) 
    @products = @search.result.page(params[:page]).per(5) 
end 

在我看來,我有:

= search_form_for @search do |f| 
    = f.label :locality_cont 
    = f.text_field :locality_cont 
    = f.submit 

回答

5

你需要把正確的URL :

= search_form_for @search, url: my_results_url do |f| 

請務必將路線中的「my_results_url」與您需要的控制器中的適當操作相匹配。

手錶this RailsCast on Ransack,其相當真棒

+0

非常感謝,這對我來說很有用! –

相關問題