如何使用form_tag中的country_selection实现国家/地区选择

时间:2013-03-18 12:44:16

标签: ruby-on-rails ruby-on-rails-3

我想在搜索表单中使用国家/地区选择,并且想知道contry_select_tag不能与form_tag一起使用

我试过了

<%= form_tag new_search_path  :html => {:multipart => true} do %>
   <%= text_field_tag :search_val%>
   <%= country_select_tag :country,[],["Germany", "France", "Austria", "Switzerland", "Netherlands", "Spain", "USA", "Russia"]%>

   <%= submit_tag "Search" %>
<%end%>

并收到以下错误消息

undefined method `country_select_tag' for #<#<Class:0xb6640828>:0xb5d06d5c>

country_select_tag更改为country_select我没有错误,但:country中的params参数仍为空

!ruby/hash:ActiveSupport::HashWithIndifferentAccess
utf8: ✓
authenticity_token: GbmhaZAuSA3s88pTz+ZQJ6mxqZ1nrTpgSlSf40vttUY=
search_val: Test
country: 
commit: Search
html: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
  multipart: 'true'
controller: searches
action: results

我是否需要使用普通select_tag并填写模型中的国家/或是否有其他解决方案

1 个答案:

答案 0 :(得分:0)

尝试删除国家/地区部分

  <%= form_tag new_search_path  :html => {:multipart => true} do %>
       <%= text_field_tag :search_val%>
       <%= select_tag :country,[],["Germany", "France", "Austria", "Switzerland", "Netherlands", "Spain", "USA", "Russia"]%>

       <%= submit_tag "Search" %>
    <%end%>

此处提供更多信息http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html