如何在Rails 3.2.8中使用Jquery?

编程入门 行业动态 更新时间:2024-10-27 11:25:58
本文介绍了如何在Rails 3.2.8中使用Jquery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我阅读的所有教程都告诉我使用"public/javascripts"文件夹.但是在Rails 3.2.8中没有这样的文件夹

All the tutorials I've read tell me to use the "public/javascripts" folder. But there is no such folder in rails 3.2.8

  • 我在哪里放置我的jquery代码?
  • Rails 3.2.8中不包含Jquery吗?
推荐答案

默认的Rails应用程序(> 3.2)在Gemfile的第23行包含jQuery gem:

The default Rails application (> 3.2) includes the jQuery gem on line 23 of the Gemfile:

gem 'jquery-rails'

您将jQuery代码放在自定义JavaScript文件(例如hello.js)中的以下路径中:

You place your jQuery code in a custom JavaScript file--e.g., hello.js--in the following path:

app/assets/javascripts/

示例:

app/assets/javascripts/hello.js

在hello.js中,确保在此块中包含jQuery代码:

In hello.js, make sure you include your jQuery code inside of this block:

$(document).ready(function() { YOUR CODE HERE });

就是这样.您已经准备在Rails中使用jQuery. (由于app/assets/javascripts/application.js中的第15行,因此可以正常工作)

That's it. You're ready to use jQuery in Rails. (This works because of line 15 in app/assets/javascripts/application.js)

//= require_tree .

此行说要包括javascripts目录中的所有内容.

This line says to include everything in the javascripts directory.

更多推荐

如何在Rails 3.2.8中使用Jquery?

本文发布于:2023-10-29 02:47:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538506.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Rails   Jquery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!