Show empty as default from dropdown

Hey I have this code:

<div class="form-group">
    <%= label f, :team_id, class: "control-label" %>
    <%= select f, :team_id, @teams, class: "form-control" %>
    <%= error_tag f, :team_id %>

which displays a dropdown from my items from the database

I get them like this:

teams =
      |>{&, &})

When i do not have team the dropdown is obviously empty, but when i have even one team i cannot select the dropdown to be empty. is there a way to do so?

1 Like

Empty is just the empty string, so add an entry with an empty string, like add this right after your teams = ... bit:

teams = [{"", ""} | teams]



FWIW select also has a prompt option that can be used to do the same thing.