回答
你需要用任何你想要的參數來調用搜索。相反的:
def index
@search = Article.search(params[:search])
@articles = @search.all # load all matching records
end
你可能有
def show
@search = Article.search(params[:search])
@articles = @search.where(:user_id => params [:user_id]).all # load all matching records
end
根據自定義Where創建
如果你想搜索行動,使用不同的路線,給url
選項form_for
。
<%= form_for @search, :url => search_results_movies_path do |f| %>
嗯,我有這在我的應用程序佈局上:'<%= form_for @search,search_results_movies_path do | f | %> <%= f.text_field:title_or_actors_or_director_contains,:class =>「span2」%> <% end %>'現在,如果我在與」電影「不同的控制器中開始搜索,它不會重定向到搜索結果。我能解決這個問題嗎? – fertech 2012-03-15 16:31:26
@fertech你必須通過選項哈希傳遞網址,如下所示:<%= form_for @search,:url => search_results_movies_path do | f | %>' – graywh 2012-12-12 16:17:31
- 1. Rails 3重定向
- 2. Rails 3爲註冊設計自定義重定向
- 3. Rails 3 - 自定義驗證
- 4. modRewrite自定義重定向
- 5. 404自定義重定向
- 6. Rails 3 meta_search sort_link和分頁
- 7. MVC 3 AuthorizeAttribute使用自定義消息重定向
- 8. 自定義重定向後登錄表單在symfony的3
- 9. 保存在Rails Admin後重定向到自定義操作
- 10. Rails 3 - 重定向用戶登錄
- 11. 與Rails的內部重定向3
- 12. Rails 3使用POST重定向
- 13. Rails 3和Webrat:錯誤的重定向
- 14. htaccess自定義重定向不工作
- 15. htaccess的WordPress的自定義重定向
- 16. IIS 7.5自定義重定向
- 17. 帶自定義頭的PHP重定向
- 18. 的.htaccess自定義參數重定向
- 19. method_for_query,重定向到自定義頁面
- 20. 將PHP重定向到自定義URL
- 21. SignalR自定義方法重定向
- 22. PHP自定義標頭重定向
- 23. htaccess 301自定義重定向
- 24. 重定向自定義網址
- 25. Rails 3 - 自定義JSON的條件
- 26. Rails 3 - 自定義驗證程序
- 27. Rails 3自定義驗證和shoulda
- 28. 用Rails 3自定義守護進程
- 29. Rails 3中的自定義記錄器?
- 30. Rails 3自定義驗證器問題
好的。但我的搜索表單是在應用程序佈局,所以我必須在應用程序控制器上過濾索引電影:'def index_movies @search = Movie.search(params [:search]) @movies = @ search.all end 「我只是採取了錯誤的做法? (對不起,我無法格式化!) – fertech 2012-03-15 16:45:04
您的搜索在'application.html.erb'? – ScottJShea 2012-03-15 16:55:00
是的,我有一個在application.html.erb – fertech 2012-03-15 17:43:35