简体   繁体   中英

How do I add JQuery from a template to my rails app?

I am pretty new at this but I learned the basics of using Rails off of Codecademy and am trying to figure out how to build a basic website using a template I found.

I have been using this template: http://templated.co/retrospect and I was able to deploy almost everything but the JQuery it uses. The Rails lesson didn't cover how to add JQuery the template provides for the menu bar action (if you press the menu button, it pulls out a sidebar with menu options).

In the template files, it provides assets/js files:

jquery.min.js,main.js,skel.min.js和util.js

I tried putting these in my app/assets/javascripts folder of my rails app, but the menu action does not seem to be working. I checking in application.js and I do have //= require_tree . in there.

Would you be able to guide me on how to make this work?

Thank you so much!

Edit: I already have the 'jquery-rails' gem installed with //= require jquery //= require jquery_ujs in my application.js

This might work: Use jquery as the JavaScript library

  1. Add this gem to your Gemfile gem 'jquery-rails'

  2. Add this to your application.js file

    //= require jquery

    //= require jquery_ujs

This way you dont need to actually have JQuery.min.js file in assets.

It seems like what ended up fixing my error was using the javascript include tag for each separate file.

Viewing the page source when it would load, the files would all import, but in one big script tag. Splitting it into different javascript include tags splits each file into separate tags which ended up working for me. I hope this can help someone!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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