Project

pjax_rails

0.33
No commit activity in last 3 years
No release in over 3 years
PJAX integration for Rails
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

PJAX for Rails

Build Status

Integrate Chris Wanstrath's PJAX into Rails via the asset pipeline.

To activate, add this to your app/assets/javascripts/application.js (or whatever bundle you use):

//=require jquery.pjax

Then choose all the types of links you want to exhibit PJAX:

// app/assets/javascripts/application.js
$(function() {
  $(document).pjax('a:not([data-remote]):not([data-behavior]):not([data-skip-pjax])', '[data-pjax-container]')
});

For this example, the PJAX container has to be marked with data-pjax-container attribute, so for example:

<body>
  <div>
    <!-- This will not be touched on PJAX updates -->
    <%= Time.now %>
  </div>

  <div data-pjax-container>
    <!-- PJAX updates will go here -->
    <%= content_tag :h3, 'My site' %>
    <%= link_to 'About me', about_me_path %>
    <!-- The following link will not be pjax'd -->
    <%= link_to 'Google', 'http://google.com', 'data-skip-pjax' => true %>
  </div>
</body>

Layouts

By default, the pjax_rails gem will not render your application layout file and will instead only return the yielded view. But if you have additional content you want to always be returned with your pjax requests, you can override pjax_layout in your controller and specify a layout to render (by default, it's false)

class ApplicationController < ActionController::Base
  def pjax_layout
    'pjax'
  end
end