Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using jquery in Rails

I am planning to use jquery in Rails instead of prototype.

I am not sure to use jRails or to use plain jquery and stay away from RJS.

What do you think about this?

EDIT: Two weeks later I found this http://www.loudthinking.com/posts/32-myth-3-rails-forces-you-to-use-prototype

EDIT: This screencast is interesting too.

like image 874
hectorsq Avatar asked Oct 29 '08 03:10

hectorsq


People also ask

Does rails come with jQuery?

Starting Rails 5.1, jQuery is not included by default. Let's add it on the Gemfile. To include the jQuery files in our application, we will require a few files on app/assets/javascripts/application. js .

Can you use JavaScript with Ruby on Rails?

Rails uses a technique called "Unobtrusive JavaScript" to handle attaching JavaScript to the DOM. This is generally considered to be a best-practice within the frontend community, but you may occasionally read tutorials that demonstrate other ways.

What is jQuery HTML?

jQuery is a lightweight, "write less, do more", JavaScript library. The purpose of jQuery is to make it much easier to use JavaScript on your website. jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code.


3 Answers

If you ask me, staying away from RJS is a great idea. RJS is an amazingly cool hack, but for production code it's a pain to test and debug. I recommend sticking to UJS (Unobtrusive JavaScript), and jQuery is a great way to do UJS.

like image 61
Avdi Avatar answered Oct 20 '22 17:10

Avdi


I second using jQuery without the help of Rails using unobtrusive Javascript as a technique. I would recommend using the Low Pro library to set up behavior controllers to bind CSS pseudo-classes (events) to your functions.

jQuery also does just fine without Rails for DOM manipulation.

like image 24
Alan Avatar answered Oct 20 '22 17:10

Alan


I use JRails and it is exc ellent.

I think there is some value to be hand with using RJS for simple operations ... much of the out-of-the-box functionality works great for simple use-cases and it helps you get a finished product out the door fast. You can always convert code at a later stage.

like image 20
Toby Hede Avatar answered Oct 20 '22 17:10

Toby Hede