来自documentation:
collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {}) public
...
:value_method 和 :text_methodparameters 是要调用的方法
在集合的每个成员上。返回值用作值
每个<option>标签的属性和内容,分别。他们能
也可以是响应调用的任何对象,例如 proc,它将是
调用集合的每个成员来检索值/文本。
那就试试吧:
<%= collection_select(:country,:id,SyncedCountry.order('name ASC'),:id,:name,{},{:class => "input-xlarge"}) %>
文档中的示例如下所示:
示例用法(为Post 的实例选择关联的Author,
@post):
collection_select(:post, :author_id, Author.all, :id,
:name_with_initial, prompt: true)
如果@post.author_id 已经是1,这将返回:
<select name="post[author_id]">
<option value="">Please select</option>
<option value="1" selected="selected">D. Heinemeier Hansson</option>
<option value="2">D. Thomas</option>
<option value="3">M. Clark</option>
</select>
(这将返回“author_id”=>“1”)
现在,我不熟悉您的模型,但如果您选择用户所在的国家/地区,我认为这应该可行:
<%= collection_select(:user, :country_id,SyncedCountry.order('name ASC'),:id,:name,{},{:class => "input-xlarge"}) %>