Having finished Hartl's great Rails Tutorial I'm now working my way through the very good jQuery - Novice to Ninja by Castledine and Sharkie. While I've able to include jquery.js and jquery-ui.js in my rails projects, I'm getting stuck when it comes to adding other jQuery plugins.
完成了Hartl伟大的Rails教程后,我现在正在通过非常好的jQuery - 由Castledine和Sharkie为Ninja的新手工作。虽然我能够在我的rails项目中包含jquery.js和jquery-ui.js,但在添加其他jQuery插件时我会陷入困境。
I've figured out that when the plugins are hosted on github, I can import them into my project using the command line and:
我已经发现当插件托管在github上时,我可以使用命令行将它们导入到我的项目中:
[my rails app]$ rails install [github URL]
The plugin gets successfully imported into the /vendor/plugin/ directory where javascript_include_tag can't find them. This situation prompts 3 questions:
插件成功导入/ vendor / plugin /目录,其中javascript_include_tag无法找到它们。这种情况提示3个问题:
-
Is there a way to import jQuery plugins into my Rails app that puts them into the public/javascripts/ directory where they belong?
有没有办法将jQuery插件导入我的Rails应用程序,将它们放入它们所属的public / javascripts /目录中?
-
If the answer to 1 is "no," is there a way to have javascript_include_tag search for scripts in vendor/plugins/? This seems like bad practice since jQuery scripts are hidden away from the public/javascript/ directory where people would normally look for them.
如果1的答案是“否”,有没有办法让javascript_include_tag搜索vendor / plugins /中的脚本?这似乎是不好的做法,因为jQuery脚本远离public / javascript /目录,人们通常会在那里查找它们。
-
If 1 and 2 are both "no's," is there a more elegant way to move the files from vendor/plugins/ than $mv or copying and pasting?
如果1和2都是“不是”,那么是否有更优雅的方式从供应商/插件/移动文件而不是$ mv或复制和粘贴?
Note: Through web searching I've come across 37signals' sprokets gem at http://getsprockets.org/ which seems like it might be useful at some point but beyond my current needs and understanding.
注意:通过网络搜索,我在http://getsprockets.org/上遇到了37signals的sprokets gem,这似乎在某些方面可能有用,但超出了我目前的需求和理解。
Grateful for any thoughts!
感激任何想法!
3 个解决方案
#1
4
Normal practice is to download a minified version of the plugin you'd like to use and save it in the public/javascripts
directory.
通常的做法是下载您想要使用的插件的缩小版本并将其保存在public / javascripts目录中。
rails install
is for Rails plugins, not jQuery plugins.
rails install用于Rails插件,而不是jQuery插件。
#2
8
In current rails version the directory would be
在当前的rails版本中,目录将是
/vendor/assets/javascripts
#3
1
If you are insistent on using rails install you could write a rake or thor task to copy the files for you.
如果您坚持使用rails install,则可以编写rake或thor任务来为您复制文件。
You could also try a symlink between the public/javascripts directory and the download directory so the stylesheet tag can just access it.
您还可以尝试在public / javascripts目录和下载目录之间使用符号链接,以便样式表标记可以访问它。
#1
4
Normal practice is to download a minified version of the plugin you'd like to use and save it in the public/javascripts
directory.
通常的做法是下载您想要使用的插件的缩小版本并将其保存在public / javascripts目录中。
rails install
is for Rails plugins, not jQuery plugins.
rails install用于Rails插件,而不是jQuery插件。
#2
8
In current rails version the directory would be
在当前的rails版本中,目录将是
/vendor/assets/javascripts
#3
1
If you are insistent on using rails install you could write a rake or thor task to copy the files for you.
如果您坚持使用rails install,则可以编写rake或thor任务来为您复制文件。
You could also try a symlink between the public/javascripts directory and the download directory so the stylesheet tag can just access it.
您还可以尝试在public / javascripts目录和下载目录之间使用符号链接,以便样式表标记可以访问它。