2013-03-18 21 views
0

我想使用搜索表單一個國家選擇使用country_selection來實現國家的選擇,想知道這contry_select_tag不工作的form_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_tagcountry_select我沒有錯誤,但:countryparams參數留空

!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,並與國家填滿它從一個模型或有另一種解決方案

回答

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

+0

是的這是一種替代的可能性。但有沒有辦法使用country_select_tag來自動獲得所有國家/地區的信息。 – kovex 2013-03-20 19:02:31

+0

是的,如果您設置了國家/地區模型並使用collection_select,則可以從模型中提取數據以填充列表。 – muttonlamb 2013-03-21 00:18:51

+0

我知道,這個想法並沒有使用單獨的國家模式。但經過一些考慮,我決定實施一個國家模式,併爲每個國家增加了一些屬性字段。 – kovex 2013-03-21 19:29:13