rails best practices where to place unobtrusive javascript

I do not think there is one best practice, but I’ll let you know what I do. I have a series of js files each for with their own purpose in the public/javascripts/ directory. Some examples could be utility.js chat.js shopping_basket.js and so on. I use asset packager and define one big fat collection for … Read more

Unobtrusive Knockout

Great question. I’ve been writing complex KnockoutJS views for awhile and was never satisfied until I switched to Ryan Niemeyer’s class binding provider. The Knockout ClassBindingProvider allows you to declare your bindings in a JavaScript object and then reference them from a data-class attribute similar to how css classes work. It works great! See an … Read more

How Does Rails 3’s “data-method=’delete'” Degrade Gracefully?

The change they made in Rails 3 with these data- attributes wasn’t about graceful degradation, it was about unobtrusive JavaScript. In Rails 2, specifying :method => :delete on a link would generate a whole bunch of inline JavaScript that would create a form with a hidden input and then submit the form. That was the … Read more

submit a rails remote form with javascript

In Rails 5.1+, which replaces the old jquery-ujs with a non-jquery rails-ujs, the above answers no longer work, always submitting the form via an HTML HTTP request. This is how you trigger the new rails submit event handler: var elem = document.getElementById(‘myform’) // or $(‘#myform’)[0] with jQuery Rails.fire(elem, ‘submit’); (Can’t tell you how long it … Read more

What is Unobtrusive Javascript in layman terms? [closed]

Checkout the wikipedia article: Unobtrusive JavaScript “Unobtrusive JavaScript” is a general approach to the use of JavaScript in web pages. Though the term is not formally defined, its basic principles are generally understood to include: Separation of functionality (the “behavior layer”) from a Web page’s structure/content and presentation Best practices to avoid the problems of … Read more

Javascript: Module Pattern vs Constructor/Prototype pattern?

Constructor-functions and prototypes are one of the reasonable ways to implement classes and instances. They don’t quite correspond to that model so you typically need to choose a particular scheme or helper method to implement classes in terms of prototypes. (Some background on classes in JS.) The module pattern is typically used for namespacing, where … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)