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.
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 .
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With