How to use :selected with grouped_collection_select

后端 未结 3 1205
逝去的感伤
逝去的感伤 2021-01-13 04:01

Is it possible to somehow use the :selected option that you\'d use on a normal select view helper with the grouped_collection_select function? I\'d like to set the value th

3条回答
  •  逝去的感伤
    2021-01-13 04:14

    Maybe too late, but the API documentation of grouped_collection_select states: 'The value returned from calling method on the instance object will be selected.'

    So, you don't even have to specify a :selected option, since Rails will automatically select based on the current value of your attribute. If subscription_plan_id has value 5, then that's what will be selected.

    If that's supposed to be a default value, then you can set it with an after_initialize in your model.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题