Question

I have a select2 selection on #user_languages

@user has an array of languages

I am trying to select those langauges with

$("#user_languages").select2( "val","<%=j @user.languages %>");

but I am getting

undefined method `gsub' for ["English", "Spanish", "French"]:Array
Was it helpful?

Solution

use to_json instead of j and double qoute(") :

$("#user_languages").select2( "val",<%=h @user.languages.to_json %>);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top