javascriptruby-on-railsrubylocaltime

Rails 'local-time' gem not running JS


I'm trying to use the local-time gem by Basecamp. Following the Readme, I added

//= require local-time

to my app/assets/config/manifest.js, which now looks like this:

//= link_tree ../images
//= link_directory ../stylesheets .css

//= require local-time

I then use the gem as prescribed:

<%= local_time(comment.created_at) %>

which, as per the Readme, renders

<time data-format="%B %e, %Y %l:%M%P"
      data-local="time"
      datetime="2013-11-27T23:43:22Z">November 27, 2013 11:43pm</time>

The Readme also claims that JavaScript, i.e., the client, would then convert this to:

<time data-format="%B %e, %Y %l:%M%P"
      data-local="time"
      datetime="2013-11-27T23:43:22Z"
      title="November 27, 2013 6:43pm EDT"
      data-localized="true">November 27, 2013 6:43pm</time>

But I can see that this does not happen for me. The markup generated by local_time remains untouched in the DOM.

In fact, the word "local" appears 0 times in the compiled application.js my browser receives.

It's possible there's something wrong with the gem, but for now I'm assuming that I'm doing something wrong. My Ruby code seems to be finding and using the gem just fine, but for some reason, the JS part never runs.

What am I doing wrong?

EDIT: I'm using Rails version 6.0.3.4, Ruby version 2.6.5p114, and local-time version 2.1.0.


Solution

  • Merovex's answer was a good temporary workaround, but according to paulanunda's comment on the GitHub issue, there is a much simpler way:

    $ yarn add local-time
    

    And instead of messing with the manifest.js file, just put the following in your application.js file:

    import LocalTime from 'local-time';
    LocalTime.start();