I have a simple_form which I am trying to get to always include a blank item in it, as a ‘nil’ value in that field has a special meaning in this database.
In order to make it more obvious for end users, I also want to title it with something along the lines of “(select if none)”.
I’m currently doing this, but it only inserts the ‘blank’ item when creating a new object, not when editing one.
# _child_form.html.erb
<%= simple_form_for @child do |f| %>
<%= f.input :first_name %>
<%= f.input :last_name %>
<%= f.association :parent, :collection => @parents, :prompt => "(select if none)" %>
<%= f.button.submit %>
<% end %>
.
# child_controller.rb
def new
@child = Child.new
@parents = Parent.all
end
def edit
@child = Child.find(params[:id])
@parents = Parent.all
end
You want to use
:include_blank, not:promptThe documentation