Rails: Rails Prototype vs Unobtrusive Javascript using jQuery

I worked on two projects using Ajax and Ruby. In one project, I used the Rails Prototype and RJS helpers. In another project, I used HAML and unobtrusive Javascript with jQuery. Each had a learning curve that I overcame. However, the long-term costs and benefits of any approach are not clear. For my next project, I am trying to decide between:

  • Rails + Haml + jRails + jQuery
  • Rails + Haml + Unobtrusive jQuery

The trend in Rails, especially Rails 3.0, seems to be aimed at using unobtrusive Javascript, but I don’t understand why it is better, especially when you get so many useful helpers (for example, remote_form_for) from Rails / jRails. Trying to make this decision, I have the following questions:

  • Which approach leads to less code to achieve the same amount of functionality?
  • Which approach is less error prone?
  • Which approach is easier to test?
  • Which approach is easier to read, maintain and develop?
  • Which approach allows you to more easily degrade your web application (providing the same functionality without Ajax) when Javascript is disabled in the client browser?

I appreciate any help or understanding you can provide.

+3
source share
1 answer

I have several answers to your questions - at least from my point of view. The answers to such questions really depend on your experience and preferences.

1) , JavaScript , JavaScript.

2 3) JavaScript . JavaScript , , , , , . , ( ), . .

js , , . , .

4) , js , , - , , . Unobtrusive js .

5) . .

, Rails 3 js, . html, js, logic, , , . , .

, .

+2

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


All Articles