SkRoR
SkRoR

Reputation: 1199

how to add default option in select tag on ruby on rails

Through select_tag i want to add a default option as select a category

here is my code

<%= select_tag 'category', options_from_collection_for_select(@categories, 'id', 'name', :onchange => 'update_subscategories_div(this.value)'%>

Upvotes: 0

Views: 519

Answers (1)

Pavan
Pavan

Reputation: 33542

You can use prompt option of select_tag

<%= select_tag 'category', options_from_collection_for_select(@categories, 'id', 'name'), prompt: "Select a Category", :onchange => 'update_subscategories_div(this.value)' %>

Upvotes: 1

Related Questions