如何使用 Rails 5.1.0 和 jQuery [英] How to use Rails 5.1.0 and jQuery

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

问题描述

我开始使用 Rails v5.1.0,据我所知,它默认没有 jQuery,但想安装 jQuery 以与 Zurb Foundation 6 一起使用.

I started using Rails v5.1.0 which I understand comes without jQuery as a default, however want to install jQuery to work with Zurb Foundation 6.

设置它的最佳方法是什么,因为基础当前没有加载模态?

What's the best way to set this up as foundation is not currently loading modals?

推荐答案

总结:

  • 安装纱线
  • yarn 添加 jquery
  • 将 jquery 添加到 application.js 清单文件
  • ~~~

    我今天也遇到了这个问题.

    I came across this problem today as well.

    这篇关于在 5.1 中使用 ActionCable 的文章中 我了解到在您的应用程序中获取 JQuery 的新方法是使用 Yarn 这是一个 javascript 依赖项管理器(想想 Gemfile 和 Bundler,但要考虑 javascript).

    In this article about using ActionCable with 5.1 I learned that the new way to get JQuery in your app is to use Yarn which is a javascript dependency manager (Think Gemfile and Bundler but for javascript).

    在 Rails 5.1 中创建新应用程序时,您会注意到一个新的可执行文件:bin/yarn.尝试在您的系统上未安装 yarn 的情况下运行此程序将提供典型的有用的下一步做什么"消息:

    You'll notice a new executable file when you create a new app in Rails 5.1: bin/yarn. Trying to run this without yarn installed on your system will lend the typical helpful "what to do next" message:

    在 https://yarnpkg.com/en/docs/install

    • 如果您在 Mac 上使用自制软件,您只需brew install yarn.

    如果你在 Windows 上使用 Chocolatey,choco install yarn.

    If you use Chocolatey on Windows, choco install yarn.

    在 Linux 上,通常的添加存储库和 sudo apt-get install yarn"适用.我会让您浏览文档页面以获取详细信息.

    On Linux, the usual "add a repo and sudo apt-get install yarn apply. I'll let you wander over to the docs page to get the details.

    完成后,您可以执行以下操作:

    Once you're yarned up, you can do:

    yarn add jquery
    

    这会将 jquery 添加到 .js 依赖文件中:package.json.这有点像您的应用程序的Javascript Gemfile",而 Yarn 是您的Bundler".

    which will add jquery to the .js dependency file: package.json. This is kind of like your application's "Javascript Gemfile", and Yarn is your "Bundler".

    既然您已经将 jquery 添加到您的项目中,您可以按照通常的方式将它包含在您的清单中.

    Now that you've got jquery added to your project, you can include it in your manifest the usual way.

    //= require jquery
    //= require rails-ujs
    //= require turbolinks
    //= require bootstrap
    //= require_tree .
    

    您还可以找到这个链接也很有帮助.这是一篇讨论在 Rails 中处理 Javascript 依赖项的新想法的文章.

    You may also find this link helpful as well. It's an article talking about the new ideas for handling Javascript dependencies within Rails.

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

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