I have a select input where the user can pick a Company. Each company has an image url, I want that when the user click on a select option, the image of the company is added next to select input. Here I want to have the data.id to return it's value so that the url can be generated with the correct image.
In my view I have
<img class="my_img" src="">
<%= select("company", "company_id", Company.all.collect {|p| [ p.name, p.id ] }, { id: "select-company"})%>
In my js.erb file I have
$('#select-company').on('select2:select', function (e) {
var data = e.params.data;
$(".my_img").attr("src", "<%= Company.find(#{data.id}).logo_url(:thumb) %>");
});