JavaScript Rails code not working in application.js -
$(document).ready(function() { $('#client-select2').select2(); });
if place code above application.js, not respond if place in _form.html.erb file, does. know why is?
views/orders/_form.html.erb
<script type="text/javascript"> $(document).ready(function() { $('#client-select2').select2(); }); </script> <%= simple_form_for(@order) |f| %> <%= f.error_notification %> <%= f.input :code %> <%= f.association :client, collection: client.all, label_method: :name, value_method: :id, prompt: "choose client", required: true, input_html: { id: 'client-select2' } %> <%= f.submit %> <% end %>
application.html.erb has
<%= javascript_include_tag 'application' %>
the reason select2 and/or jquery included after application.js,
if instance, if order is:
//=require_self //=require select2 //=require jquery
the jquery/select2 functions not available in application.js since application.js included before.
could share header of application.js?
Comments
Post a Comment