开发者

How do I publish vendor/_____/public/* files?

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/mypl开发者_开发百科ugin/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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜