Why do the Rails helper methods prevent “unobtrusive JavaScript”?

Unobtrusive just means "Don't mix your HTML with your javascript behavior". Another way to say this is "Don't change your HTML just because you want to use javascript". The rails javascript helper methods do just that in a kind of hidden way.

Unobtrusive just means "Don't mix your HTML with your javascript behavior". Another way to say this is "Don't change your HTML just because you want to use javascript". The rails javascript helper methods do just that in a kind of hidden way.

Say you weren't using javascript at all. If you wanted an HTML form you'd use form_for and have a regular form. Now say you want to add javascript so that your form submits an AJAX request instead of a regular HttpRequest.

You have two ways to do this. You can use the helper method remote_form_for You can use something like jQuery to bind a function to the submit call that submits your form via AJAX. The first method is obtrusive.

You're changing your markup (look at the generated code). The second method is unobtrusive. By using jQuery and attaching the behavior from javascript you don't alter your HTML at all.

Good explanation. Thanks. – Lee Tang Oct 25 '09 at 4:47 @Lee Tang: Always happy to help :) – Jason Punyon?

Oct 25 '09 at 4:49.

The rails helpers add the onclick events right into the html. I always thought unobtrusive meant that your page will still work when a user has javascript disabled, but after jason punyon's answer popped up while I was typing, I checked into it. Indeed the technique to completely separate javascript from the html has been labeled unobtrusive javascript.

Oct 25 '09 at 4:36 1 Further, making use of unobtrusive Javascript is generally perceived as the best way to degrade gracefully. Those that view the page without javascript won't get errors, but they won't get the "full" experience as the developer or designer intended. This is why it is important to make your pages functional even if Javascript isn't turned on.

– Jared Oct 25 '09 at 13:56.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions