How to provide an erb-file as an opal-template in rails?

97 views Asked by At

I have a rails-application (rails 5.2) with opal (0.11.1) running.

I would like to use erb-templates on client site. I followed the steps described in the official opal-docs (http://opalrb.com/docs/guides/v0.11.1/templates.html), but requiring the opalerb-file fails. sprocket claims the file could not be found:

couldn't find file 'views/user' with type 'application/javascript'

File views/user.opalerb exists.

It seems that sprockets does not handle / recognize opalerb-files, although I don't find a hint that things have to be configured.

How can I make opal with sprockets find and compile this file?

1

There are 1 answers

0
toddsundsted On

I ran into the same problem (Rails 5.2.2, Opal 0.11.4). The "opalerb" extension was not being correctly registered with Tilt and Sprockets. I addressed this locally by creating a file called "opal.rb" in config/initializers with one line:

require 'opal/sprockets/erb'

Alternatively, I was also able to fix the problem by explicitly including "opal-sprockets" in my Gemfile, pulling directly from the master branch in Github:

gem 'opal-sprockets', git: 'https://github.com/opal/opal-sprockets.git'

The final option seems to be to include "opal-haml" (even if you don't intend to use HAML). This seems to trigger initialization, although I haven't investigated why.

gem 'opal-haml'