2012-02-14 14 views
0

検索フォームを作成しようとしていますが、検索はサードパーティのサイトで行われるため、コントローラだけのモデルはありません。私はRuby on Railsで検索入力を作成する

views/items/index.html.hamlを次のように設定している:

= search_field :search, :search_input 
= submit_tag 'Search' 

views/items/search.html.haml

[email protected] do |item| 
    %h1= item.title 

controllers/items_controller.rb

def index 
    #I am unsure of what to put in here? I think 
    #I need something wich sends @search_input to my search method 
end 

def search 
    @items = some_third_party_search_method_i_wrote{ params[:search_input]} 
end 

方法1が正しくレールにparamsオブジェクトを使用していますか?検索入力の結果を含むsearchページへの検索フォームを含むindexページから取得する方法を理解できませんか?

答えて

1

あなたはおそらく、あなたのフォームはモデル/オブジェクトに結び付けられていないので、代わりにsearch_field_tagを使用したい:次に

= search_field_tag :search_input 

params[:search_input]は動作するはずです。

関連する問題