Repopulate Multiple select Box - Ruby On Rails -
i using html.erb
templates , bootstrap
.when creating post choose multiple options select box , save these values in database in form of array because i'm using serialize :column_name
option in model . works far . when try edit post , select box values donot repopulate . have tried below options
my select box in _form.html.erb
<%= form_for(@post , url: { action: @definded_action }) |f| %> <%= f.select :skills, options_from_collection_for_select(@skills , :id,:title), {}, id: "sel1" ,class: "form-control selectpicker" , multiple: true%> <% end %>
when debug in edit function fetching skills , shows me
@post.skills = ["1","2","3","4"]
in edit function i'm fetching database have tried this
@post.skills = @post.skills.map(:&to_i)
but no success. appreciated :) -
can try following, same except collection_select
:
<%= f.collection_select :skills, @skills, :id, :title, {selected: @post.skills.map(:&to_i)}, { multiple: true, id: "sel1", class: "form-control selectpicker", placeholder: "select skill."} %>
Comments
Post a Comment