Sevila
Sevila

Reputation: 311

Select with content_tag not displaying include_blank

I'm trying to display a empty option for a select option, using it:

  <%= form.select(:group_id, include_blank: true) do %>

    <% @groups.each do |group| %>
      <%= content_tag(:option, group.name, value: group.id) %>
    <% end %>

  <% end %>

This don't get any error, but not display too.

Upvotes: 0

Views: 238

Answers (1)

user13808929
user13808929

Reputation:

Weird one, but I believe your include_blank wasn't being passed in the right position. This is working for me.

  <%= form.select(:group_id, nil, { include_blank: 'Please select' }) do %>
    <% @groups.each do |group| %>
      <%= content_tag(:option, group[:name], value: group[:id]) %>
    <% end %>
  <% end %>

Upvotes: 2

Related Questions