user532339
user532339

Reputation: 189

Select ActionView::FormHelper html_options not being set

I currently have the following in my application and I am simply trying to apply a class to the select as shown below

 <%= f.select :widget_id, options_from_collection_for_select(@widgets, "id", "name"),  html_options: {class: 'form-control'} %>

According to the select helper on API dock it shows it should be set up as followed:

select(object, method, choices, options = {}, html_options = {}) public

My problem is that for some reason when I inspect the element I see:

<select id="user_widget_id" name="user[widget_id]">

I don't understand why the class is not being included.

Upvotes: 0

Views: 123

Answers (1)

rorofromfrance
rorofromfrance

Reputation: 1904

Try this:

<%= f.select :widget_id, options_from_collection_for_select(@widgets, "id", "name"), {}, {class: 'form-control'} %>

The third parameters is for options, you want to pass your html_options in the 4th parameters, and no need to actually declare "html_options" too. Hope it helps !

Official doc: select(object, method, choices, options = {}, html_options = {})

Upvotes: 2

Related Questions