Enhanced AJAX handling for Rails apps
Turboboost extends the power of Turbolinks into the forms of your Rails app and provides additional convenient AJAX handlers for forms and links. It aims to be a seemless and logical addition to any Turbolinks-rocking Rails 3.2+ app. Currently it depends on jQuery. The main features are:
In recent history Turbolinks has started to emulate some of these features with a slightly different approach. I will continue to support this library if people are still finding it useful.
Gemfilegem 'turboboost'Or to live on the very edge:
gem 'turboboost', github: 'waymondo/turboboost'Then bundle install.
application.js//= require turboboostThis will also require jQuery, jquery-ujs, Turbolinks, if not already required. If you wish to register your scripts manually, you can like so:
//= require path/to/vendored/jquery
//= require jquery_ujs
//= require turbolinks
//= require turboboost/turboboostAdd turboboost: true to your form / link helpers:
Or you can add the data attribute manually:
In its simplest server-side implementation, a basic Turboboost controller action with redirection might look like this:
def create
post = Post.create!(params[:post]) #
console.log(errors) #
console.log(flash) # -> {'notice': 'Post was successfully created.'}Turboboost also provides some options for rendering AJAX responses at specific locations in the DOM:
| Rails controller render option | jQuery function |
|---|---|
:within |
html() |
:replace |
replaceWith() |
:prepend |
prepend() |
:append |
append() |
:before |
before() |
:after |
after() |
The value can be any jQuery selector. Example usage:
respond_to do |format|
format.html
format.js { render partial: 'task', object: @task, prepend: "#todo-list" }
endNo open issues yet, or sync has not completed.