How to use jQuery in rails 3.2.8?

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

  • Where can I put jquery code?
  • not jQuery included in Rails 3.2.8?
+4
source share
3 answers

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

gem 'jquery-rails' 

You put jQuery code in a custom JavaScript file - for example, hello.js - in the following way:

 app/assets/javascripts/ 

Example:

 app/assets/javascripts/hello.js 

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

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

What is it. Are you ready to use jQuery in Rails. (This works because of line 15 in app/assets/javascripts/application.js )

 //= require_tree . 

This line talks about including everything in the javascripts directory.

+16
source

You need a gem. Perhaps this will help you:

http://c.kat.pe/post/how-to-use-jquery-for-rails-3/

0
source

You can write jquery code and put the file as file_name.js in the Javascript folder and call that file in your layout file. You can link http://jqueryui.com/

0
source

Source: https://habr.com/ru/post/1447337/


All Articles