how to add default blank value in select field (amber framework)?

== select_field(name: "parent_category_id", collection: Category.all.map{|category| [category.id, category.name]}, selected: "", class: "form-control")

1 Answers

0
igneus On

Make use of the fact that Crystal Arrays can be concatenated:

c = [["", "blank"]] + Category.all.map{|category| [category.id, category.name]}
select_field(
  name: "parent_category_id", 
  collection: c, 
  selected: "", 
  class: "form-control"
)