在Rails 3中使用jQuery插件 [英] Using jQuery plugins in Rails 3

查看:116
本文介绍了在Rails 3中使用jQuery插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完成了Hartl出色的 Rails教程,我现在正在研究Castledine和Sharkie编写的非常好的 jQuery-Ninja新手.虽然我可以在我的rails项目中包含jquery.js和jquery-ui.js,但是在添加其他jQuery插件时我还是会陷入困境.

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.

我发现,当插件托管在github上时,我可以使用命令行将其导入到我的项目中:

I've figured out that when the plugins are hosted on github, I can import them into my project using the command line and:

[my rails app]$ rails install [github URL]

该插件已成功导入到/vendor/plugin/目录,在该目录下javascript_include_tag找不到它们.这种情况会提示3个问题:

The plugin gets successfully imported into the /vendor/plugin/ directory where javascript_include_tag can't find them. This situation prompts 3 questions:

  1. 是否可以将jQuery插件导入到我的Rails应用中,从而将它们放入它们所属的public/javascripts/目录中?

  1. Is there a way to import jQuery plugins into my Rails app that puts them into the public/javascripts/ directory where they belong?

如果对1的回答为否",是否有办法让javascript_include_tag在vendor/plugins/中搜索脚本?这似乎是一种不好的做法,因为jQuery脚本被隐藏在人们通常会寻找它们的public/javascript/目录之外.

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和2均为"no",是否有比$ mv更好的从供应商/插件/移动文件或复制和粘贴的方式?

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?

注意:通过网络搜索,我在 http://getsprockets.org/上遇到了37signals的sprokets gem.在某些时候似乎很有用,但超出了我目前的需求和理解.

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.

感谢您的任何想法!

推荐答案

通常的做法是下载您要使用的插件的缩小版本,并将其保存在public/javascripts目录中.

Normal practice is to download a minified version of the plugin you'd like to use and save it in the public/javascripts directory.

rails install用于Rails插件,而不是jQuery插件.

rails install is for Rails plugins, not jQuery plugins.

这篇关于在Rails 3中使用jQuery插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆