我已经尝试在collection_select字段上添加required => true和:prompt =>“select ...”,但每次出现语法错误。如何解决下面这个错误。
.field
= f.label "Receiver"
= f.collection_select(:receiver_admin_id,
Admin.agent_and_admin(current_admin.id, current_admin.parent_master_agent_id),
:id,
:agent_name,
:prompt => 'Select receiver',
{multiple: true}),
:required => true
= f.collection_select(:receiver_admin_id,
Admin.agent_and_admin(current_admin.id, current_admin.parent_master_agent_id),
:id,
:agent_name,
:prompt => 'Select receiver',
{multiple: true, required: true})
= f.collection_select(:receiver_admin_id,
Admin.agent_and_admin(current_admin.id, current_admin.parent_master_agent_id),
:id,
:agent_name,
:prompt => 'Select receiver',
{},
{multiple: true}),
:required => true
= f.collection_select :receiver_admin_id,
Admin.agent_and_admin(current_admin.id, current_admin.parent_master_agent_id),
:id,
:agent_name,
:prompt => 'Select receiver',
{multiple: true},
:required => true
请试试这个:
= f.collection_select :receiver_admin_id, Admin.agent_and_admin(current_admin.id, current_admin.parent_master_agent_id), :id, :agent_name, {prompt: 'Select receiver'}, {multiple: true, required: true}
几乎每次都很接近:)从文档in the rails guide你有:
collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})
使用表单助手(f.
)意味着对象(第一个参数)被处理,所以你留下:
method, collection, value_method, text_method, options, html_options
多个和必需都需要在html_options中:
= f.collection_select(:receiver_admin_id, Admin.agent_and_admin(current_admin.id, current_admin.parent_master_agent_id), :id, :agent_name, { :prompt => 'Select receiver' }, multiple: true, :required => true)