简体   繁体   中英

Rails gem with javascript files

I'm trying to create a ruby gem for rails out of a plugin I've created. The problem is that my plugin 'shortcuts' uses a few javascript files which need to be in the public/javascripts directory to work.

What's the best way to make these javascript files which are in the gem I've created accessible by which ever project requires my gem?

Add a rails generator to your gem such that script/generate <yourgem> puts the javascript files in the correct location.

For more information, see the How to Make a Generator Railscast.

As an example, the formtastic gem has a generator that puts its specific stylesheets in the correct location -- similar to your javascript problem.

Another example, nifty-generators is just a gem with useful generators.

您可以通过制作postinstall.rb来复制它们,这将在安装插件后自动执行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM