简体   繁体   English

Rails gem与javascript文件

[英]Rails gem with javascript files

I'm trying to create a ruby gem for rails out of a plugin I've created. 我正在尝试使用我创建的插件为rails创建一个ruby gem。 The problem is that my plugin 'shortcuts' uses a few javascript files which need to be in the public/javascripts directory to work. 问题是我的插件“快捷方式”使用了一些需要在public / javascripts目录中运行的javascript文件。

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? 什么是制作这些javascript文件的最佳方法,这些文件位于我创建的gem中,可以访问哪个项目需要我的gem?

Add a rails generator to your gem such that script/generate <yourgem> puts the javascript files in the correct location. 向gem中添加rails生成器 ,以便script/generate <yourgem>将javascript文件放在正确的位置。

For more information, see the How to Make a Generator Railscast. 有关更多信息,请参阅如何生成生成器 Railscast。

As an example, the formtastic gem has a generator that puts its specific stylesheets in the correct location -- similar to your javascript problem. 作为一个例子, formtastic gem有一个生成器,可以将其特定的样式表放在正确的位置 - 类似于你的javascript问题。

Another example, nifty-generators is just a gem with useful generators. 另一个例子, 漂亮的生成器只是一个有用的生成器的宝石。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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