Ken Collins will take a quick look at what is happening with Rails 5 and how you might avoid writing tons of modern JavaScript.
1Winning with Ajax + pushState + RailsTurbo Applications
View Slide
2FAIRFAX, V IRGI NIA T WO T HOU SA N D FI F TE E N
Turbolinks3Turbolinksv3.0v3.0
4pjax - overview.--./ \## a a( '._)|'-- |_.\___/_ ___pjax___."\> \Y/|/ \ \_\/ / '-' /| --'\_/|/ | _/|___.-' | |`'`| | || / './/__./` | |\ | |\ | |; | |/ | |jgs |___\_.\_`-"--'---'https://github.com/defunkt/jquery-pjax• pushState + ajax• HTML from server.• Replace page content.• Changes current URL.• No reload page layoutincluding CSS & JS.• Appearance of a fastpage load.
5pjax - usageMy SiteGo to next page.https://github.com/defunkt/jquery-pjax$(document).pjax('a', '#pjax-container')
pjax - on GitHub6
pjax - on GitHub7
8pjax - configuration(s)def indexif request.headers['X-PJAX']render layout: falseendendhttps://github.com/defunkt/jquery-pjax
9Convention
10ConventionKathy Sierra
Turbolinks• Replace the entire by default.• Opt-in to replace specific elements.• jQuery not required. Lightweight.• Doesn’t rely on tailored server sideresponses. Python, Django, PHP,Grails, ASP.NET• Don't make me think Rails integration.11
12INKOVATE - Hackathon App
13INKOVATE - Normal GETsclass IdeasController < ApplicationControllerdef index@ideas = Idea.order(order_clause)endend
14INKOVATE - Simple POST
15INKOVATE - Simple POST
16INKOVATE - Simple POSTfollowings_path(@idea),method: :post do %>Follow Idea
17INKOVATE - Simple POSTfollowings_path(@idea),method: :post,remote: true do %>Follow Idea
18INKOVATE - Simple POSTclass FollowingsController < ApplicationControllerdef create@idea = Idea.find params[:idea_id]@idea.followers << current_userchanged = ['iv-Main-flash', 'iv-FollowActions', 'iv-Followers']redirect_to @idea, change: changed,flash: {info: 'Following this idea!'}endend
19INKOVATE - Flash Messagesclass="iv-Main-flash"data-turbolinks-temporary>
20INKOVATE - Simple POST
21Hot Spots
22INKOVATE - Simple POST
23INKOVATE - Simple POST
Turbolinks - Hot Spots24• Single $(document).on('page:partial-load', ƒ(e) {…} handler and delegation.• Changing Fast. Official v5 is coming.
25What Now?
26Ken Collins @CustomInkTechThanks!