0

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?

Steve Ross
  • 4,134
  • 1
  • 28
  • 40

2 Answers2

1

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.

Elia Schito
  • 989
  • 7
  • 18
1

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.

djboardman
  • 152
  • 8
  • I'm going to mark this as the correct answer. I tried to port Chronic to RubyMotion and could not because it uses `require` and that's not supported. These are hands-down the best time libraries, but they rely on features defined in the core Ruby spec but omitted in some implementations. Sigh. Obviously, @elia's answer was also correct, but SO makes me choose one or the other. – Steve Ross Dec 06 '15 at 19:54
  • no problem, keep this as the right answer :) – Anyway I found that most gems will accept PRs for avoiding the use of mutable strings as they're seldom a perf bottleneck. – Elia Schito Dec 09 '15 at 12:08