I want to add the bootstrap-datepicker to my project. I did it this way.
Gemfile:
source 'https://rails-assets.org' do
gem 'font-awesome-sass', '~> 4.5.0'
gem 'rails-assets-bootstrap-sass', '~> 3.3.6'
gem 'rails-assets-bootstrap-datepicker', '~> 1.6.0'
end
_form.html.erb :
<div class="row">
<div class="col-md-2">
<%= f.input :publish_at, as: :string, input_html: { class: 'datepicker',
value: (Time.now + 1.day).strftime('%d/%m/%Y') } %>
</div>
</div>
I created a file named datepicker.js within app / assets / javascripts:
$('.datepicker').datepicker({
language: 'pt-BR',
format: 'dd/mm/yyyy',
startDate: '0d',
autoclose: true,
keyboardNavigation: false,
todayHighlight: true
});
alert("hello");
alert is working, though it's as if I'm not picking the '.datepicker' class from my _form.html.erb . When I put the same javascript code inside my _form.html.erb within a tag tag the datepicker works fine, however I did not want to insert the script tag into every view that contains a datepicker. p>