GangstaGraham
GangstaGraham

Reputation: 9355

Add Custom HTML ID to Rails Select Box

Usually, adding an ID tag at the end of a rails form helper, does the trick. However, this does not seem to be working for select boxes. What am I doing wrong?

<%= form_for(@song) do |f| %>
    <%= f.select :category, [['Pop', 1], ['Rap', 2]] , :id=>"choose-category"%>
<% end %>

^The ID is not getting set here properly, what am I doing wrong?

Thanks.

Upvotes: 2

Views: 3557

Answers (1)

toro2k
toro2k

Reputation: 19230

The select method takes four arguments, html_options is the fourth, therefore you have to pass an empty hash as the third parameter (options):

f.select(:category, [['Pop', 1], ['Rap', 2]], {}, :id => "choose-category")

Upvotes: 7

Related Questions