如何获取搜索表单以实际执行搜索查询(在Rails中)

时间:2014-04-05 14:12:26

标签: html ruby-on-rails search ruby-on-rails-4 haml

我有一个我从this tutorial创建的搜索表单。但是如何让它为指定的控制器和指定的操作执行实际查询?

%form
  %input{:placeholder => "Find something...", :required => "", :type => "text"}
    %button{:type => "submit"} Search

1 个答案:

答案 0 :(得分:0)

您需要为表单添加目标:

%form{ :action => "/rotas", :method => "get" }
  %input{:placeholder => "Find something...", :required => "", :type => "text"}
    %button{:type => "submit"} Search

或者您可以使用form_tag helper,例如:

=form_tag(controller: :posts , action: :index, method: :get) do |f|
  = f.text_field :query, nil, :placeholder => "Find something..."
    = f.submit "Search"

并记得留意indentations