Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JS for Rails Developers (is jQuery OK?)

JS for Rails Developers (is jQuery OK?)

Tour of Rails' JavaScript features: helpers, server-side concerns, and Turbolinks.

Bruno Cunha

August 17, 2015
Tweet

More Decks by Bruno Cunha

Other Decks in Technology

Transcript

  1. Agenda • Why? • AJAX • Unobtrusive JavaScript • Rails

    Helpers • Server-side Concerns • Turbolinks • Final Thoughts
  2. Why? JavaScript • Gut check • The best way •

    Client satisfaction jQuery • Easy
  3. AJAX Traditional Request-Response cycle • Client fetches full page and

    assets • Assemble everything together Asynchronous JavaScript and XML • Client fetches and renders data via JavaScript • Only update changed parts
  4. Unobtrusive JavaScript Separation of concerns • Avoid mixing presentation, layout,

    and behavior • Use data attributes to store private data
  5. Rails Helpers Form Options • Remote submits request using AJAX

    Link and Button Options • Also accept remote • Method changes request type • Confirm prompts the user after the request is made • Disable-with prevents multiple form submissions
  6. Turbolinks • Makes apps faster by persisting assets and only

    rendering body changes • Other features include transition cache, opt-out, and progress bar • Uses custom page events, use jquery-turbolinks • 3rd-party plugins are problematic
  7. Final Thoughts User experience simply matters • Performance is easy

    and good Further Reading • Slack’s $2.8 Billion Dollar Secret Sauce - https://medium.com/@awilkinson/slack- s-2-8-billion-dollar-secret-sauce-5c5ec7117908 • Working with JavaScript in Rails - http://guides.rubyonrails.org/ working_with_javascript_in_rails.html • A Tour of Rails’ jQuery UJS - https://robots.thoughtbot.com/a-tour-of-rails-jquery-ujs • How I Use Turbolinks - https://pooreffort.com/blog/how-i-use-turbolinks/