Top Banner
Rails Concerns and Turbolinks Presented by Zahidul Hasan
17

Rails Concerns and Turbolinks

Jan 22, 2018

Download

Technology

Nascenia IT
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Rails Concerns and Turbolinks

Rails Concerns and Turbolinks

Presented by

Zahidul Hasan

Page 2: Rails Concerns and Turbolinks

What is Concerns?

• Concerns provides a way that allow us to keep our code organizedand DRY

• Basically, the idea is to extract common and/or context specific chunks of code in order to clean up the models/controllers and avoid them from getting too fat and messy

Page 3: Rails Concerns and Turbolinks

More Information

• Concerns are supported by Rails 3 but have become more official in Rails 4

• Those who have worked with a Rails 4 app, might have probably noticed the app/models/concerns and app/controllers/concernsdirectories

Page 4: Rails Concerns and Turbolinks

Why should we use concerns?

• DRYing up model codes

• Skin-nizing Fat Models

Page 5: Rails Concerns and Turbolinks

DRYing up model codes

Page 6: Rails Concerns and Turbolinks

Create a commentable.rb file in app/model/concerns

Page 7: Rails Concerns and Turbolinks

Skin-nizing Fat Models

Page 8: Rails Concerns and Turbolinks

• Create a attendable.rb file in app/model/concern/event folder

Page 9: Rails Concerns and Turbolinks

• Create a commentable.rb file in app/model/concern/event folder

Page 10: Rails Concerns and Turbolinks
Page 11: Rails Concerns and Turbolinks

Controller Concerns

• Controllers can also have concerns

• Purpose will be the same: DRYing

Page 12: Rails Concerns and Turbolinks

Turbolinks

• Feature of rails 4

• Prevents the browser from reloading the JavaScript and CSS between each page change

• Its almost similar to PJAX

Page 13: Rails Concerns and Turbolinks

JavaScript pushState

• Javascript API for HTML5: History Interface

• pushState can be used to store the navigation history

Page 14: Rails Concerns and Turbolinks

PJAX

• PJAX is a combination of the terms pushState and AJAX

• Instead of reloading the whole page when clicking a link, just load the part of the page that needs updating

• On the client-side we have to define the container that should be replaced when a link is clicked

Page 15: Rails Concerns and Turbolinks

Turbolinks

• Instead of replacing only parts a page it loads a complete website from the server and replaces the <title> and <body> in the currently loaded DOM

• Unlike PJAX we don't have to mark links and containers, Turbolinkswill handle that for us

Page 16: Rails Concerns and Turbolinks

Comparison between Turbolinks and PJAX

• Turbolinks definitely improve client-side page loading, but the server still has to render the complete website

• PJAX renders only those parts of a website that really need to be updated, need additional work when developing the application

• Turbolinks will improve page load significantly if the pages share JavaScript and CSS styling. PJAX comes in handy, when server-side performance is an issue

Page 17: Rails Concerns and Turbolinks

Thank You