0

I've generated the _form.html.erb view in Fields::Belongs_to to customize the select element but I can't seem to make include_blank: false to work. Here is my code. I've already search on the correct syntax of using include_blank in select block.

<div class="field-unit__label">
  <%= f.label field.permitted_attribute %>
</div>
<div class="field-unit__field">
  <%= f.select(field.permitted_attribute, include_blank: false) do %>
    <%= options_for_select(field.associated_resource_options, field.selected_option) %>
  <% end %>
</div>

edit: value of include_blank in code

brynmrk
  • 23
  • 1
  • 4
  • Can you try this ? `<%= f.select field.permitted_attribute, options_for_select(field.associated_resource_options, field.selected_option), { include_blank: true } %> ` – Kedarnag Mukanahallipatna Sep 27 '18 at 05:39
  • @KedarnagMukanahallipatna I've editted the code since I got a typo, but doing what you suggests with `false` as the value still doesn't work. – brynmrk Sep 27 '18 at 06:02
  • Are you setting `required: true` anywhere ? – Kedarnag Mukanahallipatna Sep 27 '18 at 06:33
  • You can check this [link](https://apidock.com/rails/ActionView/Helpers/FormTagHelper/select_tag#1353-Showing-the-select-with-a-value-previously-known), I think this happens because of the syntax. – John Baker Sep 27 '18 at 10:01
  • @JohnBaker If I'd change to using select_tag it raises an error that its undefined method – brynmrk Sep 27 '18 at 23:24
  • @KedarnagMukanahallipatna I had set the belongs_to in my model as `optional: true`, but even if I'd removed that it still doesn't work – brynmrk Sep 28 '18 at 02:01
  • Can you try `= f.select field.permitted_attribute, options_for_select(field.associated_resource_options, field.selected_option), { include_blank: false} , { class: "form-control" } `. Refereing to the signature `select(object, method, choices = nil, options = {}, html_options = {}, &block) public` – John Baker Sep 28 '18 at 08:06
  • I think I've found the reason why it doesn't work, Im gonna try to submit an issue with administrate since I think it's in their codebase, though thanks @JohnBaker – brynmrk Sep 30 '18 at 23:27

1 Answers1

0

Try this:

<%= f.select(field.permitted_attribute, include_blank: "Choose...") do %>
Sjors Branderhorst
  • 2,138
  • 17
  • 25