Yeggeps
Yeggeps

Reputation: 2105

Add asset path in rails mountable engine?

How can I add vendor/assets/javascripts/mymountableengine or vendor/assets/stylesheets/mymountableengine to my mountable engine's assets paths? I want to be able to require files from these folders in my mountable engine's application.js/application.css file with sprockets.

Rails 3.2.2

Thanks.

Upvotes: 12

Views: 10254

Answers (2)

Pavel Evstigneev
Pavel Evstigneev

Reputation: 5116

I do like this:

module MyEngine
  class Engine < ::Rails::Engine

    config.assets.paths << File.expand_path("../../assets/stylesheets", __FILE__)
    config.assets.paths << File.expand_path("../../assets/javascripts", __FILE__)
    config.assets.precompile += %w( my_engine.css )

  end
end

Upvotes: 8

Yeggeps
Yeggeps

Reputation: 2105

Turns out they were already loaded! Just put them in the wrong directory: engine/vendor/assets/javascripts/engine - putting them in engine/vendor/assets/javascripts made them requireable. For others, just check Rails.application.config.assets.paths to see which paths are loaded, I believe engines use the parents Sprockets environment, so to add paths just use Rails.application.config.assets.paths << "path/here"

Upvotes: 9

Related Questions