【问题标题】:f.country_select options default countryf.country_select 选项默认国家
【发布时间】:2015-10-19 15:43:37
【问题描述】:

在我的 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'

【问题讨论】:

  • @user.country 是什么?你能用@user.country || "Select one value"吗?

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


【解决方案1】:

应该是这样的:

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

【讨论】:

  • 已更新问题。我正在使用gem 'country_select'
猜你喜欢
  • 2018-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-23
  • 1970-01-01
  • 2012-12-15
  • 1970-01-01
相关资源
最近更新 更多