Since you are replacing the content of the #container
you need to bind the select2
or any other events for that matter with the jQuery
on
method (http://api.jquery.com/on/).
So doing the following should solve your issue:
On your js.erb
:
$("#container").html("<%= j render partial: 'form' %>").trigger('show');
Then on your assets/javascripts/somefile.js.erb
, as long as somefile.js.erb
is included in your application.js
, or you could even place the following at the bottom of your application.js
:
$('#container').on('show', function() {
$('.select-list').select2();
});