我是Ruby on rails的新手。现在我在我的主页上有一个搜索表单。当我在表单中输入内容(如abc)并提交时,我希望该页面在我的控制器info
中调用我的操作search
。我该如何配置路线?
当前网址为~/info/?utf8=%E2%9C%93&location=berkeley&commit=submi
t
<div id='search_form'>
<%= form_tag('info/',method: "get") do %>
<%= text_field_tag('location', @location, :size => 30) %>
<%= submit_tag "submit", class: "btn btn-large btn-primary" %>
<% end %>
</div>
答案 0 :(得分:1)
将以下内容添加到路线文件中:
get '/info', to: "search#info", as: 'search_info'
这会为您提供search_info_path
,您可以在form_for
声明中使用它,如下所示:
<%= form_tag(search_info_path, method: "get") do %>
答案 1 :(得分:0)
<%= form_tag some_path, method: "get" do %>
<%= text_field_tag('location', @location, :size => 30) %>
<%= submit_tag "submit", class: "btn btn-large btn-primary" %>
<% end %>
您可以在form_tag中使用通向控制器的路径助手。
我认为这是错误的('info/',method: "get")
运行rake routes
以寻找帮助者