在 Volt 项目中放置前端“require”文件的位置

Where to put frontend `require` files in a Volt project

我正在编写一个应用程序,要求我在控制器外部定义 Ruby class,然后在控制器内实例化它。

我把它放在 lib/my_file.rbinitializers/client/my_file.rb 中,得到了相同的结果:

Sprockets::FileNotFound at / couldn't find file 'client/my_file' with type 'application/javascript'

通过在 main/config/initializers 中执行此操作修复了它:

if RUBY_PLATFORM == 'opal' require_relative 'client/my_file' else end