[英]Make the default option of select tag to be of current value of name in Rails
这段代码在我的“编辑用户属性”页面中。 我的Rails应用程序中有我的模型用户的subscription_type:string属性。 该属性的默认值为“”。 我希望select标记显示该选项的特定用户的值为subscription_type的当前值(“”,“ Silver”,“ Gold”或“ Platinum”)。 我该如何实现?
<select class="form-group" name = "user[subscription_type]">
<option value="">Select your subscription type</option>
<option value="Silver">Silver</option>
<option value="Gold">Gold</option>
<option value="Platinum">Platinum</option>
</select>
您将要使用select_tag和options_for_select方法并将其传递给一个数组数组,例如
options_for_select([['Gold', 'Gold'], ['Silver', 'Silver'],['Platinum', 'Platinum']], @user.subscription_type)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.