Reputation: 570
I have the following in my View:
<%= f.select :blood_group, options_for_select([
['O+', Membership.blood_groups.keys[0]], ['O-', Membership.blood_groups.keys[1]],
], @user.blood_group) %>
How do I add include_blank
attribute to the above? When I just append it at the end, I get the error "wrong number of arguments (given 3, expected 1..2)"
Upvotes: 0
Views: 658
Reputation: 2973
You can do this following as:
<%= f.select :blood_group, options_for_select([
['O+', Membership.blood_groups.keys[0]],
['O-', Membership.blood_groups.keys[1]]], @user.blood_group, {include_blank: true}, {}) %>
You can refer document at: options_for_select
Upvotes: 0
Reputation: 1260
You could do it this way:
<%= f.select :blood_group, [['', nil], ['one', 1], ['two', 2], ['three', 3], ['four', 4], ['five', 5], ['', nil]]
its optional to specify options_for_select
note that this add two blanks field at the beginning and in the end.
Upvotes: 1