Search code examples
rubyrequiremixinsvoltrb

Requiring files in the Volt Framework


I have a mixin I want to include in a few different classes in a Volt app. Pertinent structure as follows:

Including file path: app/component_1/models/my_model.rb

Included file path: app/component_2/mixins/my_mixin.rb

Here's what I've tried:

require "#{Volt.root}/app/component_2/mixins/my_mixin" yields this error in the server output when loading a page: SyntaxError: Cannot handle dynamic require

require "app/component_2/mixins/my_mixin" yields this error when starting the server: in `require': cannot load such file

require_relative "../../component_2/mixins/my_mixin" yields this error in the server output when loading a page: Opal::Builder::MissingRequire: A file required by "app.rb" wasn't found. can't find file: "../../component_2/mixins/my_mixin"

require "./app/component_2/mixins/my_mixin" yields this error in the javascript console when loading a page: Uncaught RuntimeError: no routes match path: /

Not sure what else to try?


Solution

  • Sorry this is unclear, I'll try and update the docs to make it easier. So the app folder is what's on the load path. So you can require from there.

    require 'component_2/mixings/my_mixin'