2015-10-19 85 views
0

在我的Rails应用程序中,如果用户提供了国家/地区,我希望f.country_select为user's country。否则我希望它具有Select one valuef.country_select选项默认国家

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

上述代码有问题吗?

更新:使用gem 'country_select'

上午。

+0

什么'@ user.country'?你可以使用'@user.country ||吗? “选择一个值”? – radubogdan

回答

0

它应该是这样的:

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

已更新该问题。我正在使用'gem'country_select''。 – rAzOr