f.country_select选项默认国家/地区

时间:2015-10-19 15:43:38

标签: ruby-on-rails html-select country

在我的rails应用中,如果用户提供了国家/地区,我希望f.country_select为user's country。否则我希望它有Select one value

<%= f.country_select :country, nil, {:selected => @user.country, :include_blank => 'Select one'}, {:class=>'form-control'} %>

上述代码有什么问题吗?

更新

使用gem 'country_select'

1 个答案:

答案 0 :(得分:0)

应该是这样的:

<%= f.select(:country, options_for_select(Country, :selected => @user.country), :prompt => 'Select one' , {:class=>'form-control'}) %>