views:

42

answers:

2

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.

A: 

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...)

rogerdpack
Yeah, I am wondering if anyone else knows a better way.
Jason Noble
appears there's not yet http://piotrsarnacki.com/2010/07/06/rsoc-status-briging-engine-closer-to-application/
rogerdpack
+1  A: 

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

Keith Schacht
Funny story, your blog post lists Jon Swope as a source. I happen to work with Jon. :)
Jason Noble
Lol, you took the long way around the office. :)
Keith Schacht