Eduardo Humberto
Eduardo Humberto

Reputation: 485

What is the correct way to use moment.js locale in rails?

I'm following these links to change the locale of my datepicker but it still not working.

There are no console log error's when the page is loaded.

Links:

https://eonasdan.github.io/bootstrap-datetimepicker/#using-locales
https://github.com/moment/moment

My code:

gemfile

gem 'momentjs-rails', '>= 2.9.0'
gem 'bootstrap3-datetimepicker-rails', '~> 4.17.47'

application.js

//= require moment
//= require bootstrap-datetimepicker
//= require moment/pt-br

dashboard.js

$(document).ready(function () {
    $('.datetimepicker').datepicker({
        locale: 'pt-br'
    });
});

html.erb file:

           <div class='col-md-6'>
              <div class="form-group">
                <%= label_tag :initial_date, 'Data Inicial' %>
                <div class='input-group date' id='initial_date'>
                  <%= text_field_tag(:initial_date, @filter&.initial_date, class: "form-control datetimepicker", id: "datetimepicker", autocomplete: "off") %>
                  <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                  </span>
                </div>
              </div>
            </div>

Upvotes: 1

Views: 3447

Answers (1)

Kenneth Rosales
Kenneth Rosales

Reputation: 230

I recommend using yarn if you are using a version of rails 5> 0, here you can see some useful links: http://nithinbekal.com/posts/yarn-rails/ yarn add moment https://momentjs.com/

Upvotes: 2

Related Questions