I was working with AngularJS directives and Rails 4 in order to make the bootstrap-datepicker jquery plugin work on a Rails 4 erb template, the code that I used inside the text_field_tag
is the following:
<%= text_field_tag(:start_day, nil, class: 'form-control', datepicker: 'datepicker') %>
It's important to notice that this works with AngularJS directives, the code that you get on the DOM is as follows:
<input class="form-control" datepicker="datepicker" type="text">
I worked with the directive in the following way:
timeAdminCal.directive('datepicker', function(){
return {
restrict: 'A',
link: function ($scope, $element) {
$element.datepicker({
format: 'd/m/yyyy',
autoclose: true,
todayHighlight: true
});
}
}
});
Notice that, according to AngularJS directive docs you can restrict
a class name, so you may use any class name on your text_field_tag
and it will work too.
timeAdminCal.directive('datepicker', function(){
return {
restrict: 'C', // Bind DOM element by class name 'datepicker'
link: function ($scope, $element) {
$element.datepicker({
format: 'd/m/yyyy',
autoclose: true,
todayHighlight: true
});
}
}
});