Has Anyone Used Chronic or ChronicDuration in VoltRB?

51 Views Asked by At

I've put the chronic and chronic_duration gems in my Gemfile, and everything works fine in volt console. However, if I try anything on the client side, I get a name error. I tried requiring them in a client-side initializer, but that didn't help.

Any tips?

2

There are 2 best solutions below

2
djboardman On BEST ANSWER

Just to add to Elia's answer, in Volt you can put use_gem in config/dependencies.rb (in the docs here)

This does work to load Chronic but it looks like Chronic won't run in Opal because it uses mutable strings - I get the following error:

Uncaught NotImplementedError: #<< not supported. Mutable String methods are not supported in Opal.

0
Elia Schito On

You need to add the gem's paths to the paths Opal/sprockets searches looking for files.

For gems there's a nice helper:

 Opal.use_gem "chronic"

That should go in CRuby code (MRI) as early as possible during the initialization process.