Help with rails collection_select [edited]

I am trying to implement this jquery plugin for my application. I need help trying to get something like this

<select name="user[university_id]" id="user_university_id" class="selectable">
    <option value="1" title="uni1">Uni1</option>
    <option value="2" title="uni2">Uni2</option>
</select>

using the rails helper ... the problem is that helpers never output the title attribute in the option tags. This is important for this plugin.

please help, thanks in advance

Edit: my current rails code

<%= f.collection_select(:university_id,University.all,:id,:name) %>

which just outputs

<select name="user[university_id]" id="user_university_id">
        <option value="1">Uni1</option>
        <option value="2">Uni2</option>
    </select>

So basically I need a way to add a title attribute to my parameters.

0
source share
1 answer

You could just add it using jQuery if you don't go to the rails helper route:

$(function () {

    $('select.selectable option').each(function () {
        $(this).attr('title', $(this).text());
    });

});
+1
source

Source: https://habr.com/ru/post/1752873/


All Articles