Reputation: 3766
I have installed a plugin to my Rails app. The plugin has files in its public directory that I want to make available.
For example, vendor/plugins/myplugin/public/javascripts/myplugin.js. Can I make this available via Rails at /javascripts/myplugin.js?
I've got it working by copying the files from vendor/plugins/______/public/* to public/*, but that seems like a bad idea.
Upvotes: 2
Views: 212
Reputation: 1993
I think this only works if you make your plugin into an engine. Engines can access deeper into the rails initialization process so they can add an additional static asset path.
Here is a snippet of my engine.rb file that does this:
module MoxieForum
class Engine < Rails::Engine
initializer "static assets" do |app|
app.middleware.use ::ActionDispatch::Static, "#{root}/public"
end
end
end
I recently wrote a handy starting point for creating a rails 3 engine that has this and lots of other basic functionality built in:
http://keithschacht.com/creating-a-rails-3-engine-plugin-gem
Upvotes: 3
Reputation: 66781
with rails 2.1 at least copying used to be "the only way" (I think it probably still is, though you could use mod_rewrite apache module to get them all...)
Upvotes: 0