Skip to content

Instantly share code, notes, and snippets.

@dineshsprabu
Forked from livando/pjax
Last active April 25, 2017 05:45
Show Gist options
  • Save dineshsprabu/4867c70b898874f3da7e43d6ee59040a to your computer and use it in GitHub Desktop.
Save dineshsprabu/4867c70b898874f3da7e43d6ee59040a to your computer and use it in GitHub Desktop.
[RAILs] Pjax implementation in Rails
1) add gem
2) create vendor directory, and download script
3) configure application.rb
4) write js that points the trigger to the displayer
5) ensure the trigger has the correct jquery selector
6) ensure the displayer has the correct jquery selector
1) add gem
gem 'rack-pjax'
2) create vendor directory, and download script
$ mkdir -p vendor/assets/javascripts
$ curl https://raw.github.com/defunkt/jquery-pjax/master/jquery.pjax.js > vendor/assets/javascripts/jquery.pjax.js
3) configure application.rb
module Store
class Application < Rails::Application
config.middleware.use Rack::Pjax
end
end
4) write js that points the trigger to the displayer
//= require jquery.pjax
$(document).pjax( '.code a', '[data-pjax-container]')
5) ensure the trigger has the correct jquery selector
<div class="code">
<%= link_to code_topic.name, :code_id => code_topic %>
6) ensure the displayer has the correct jquery selector
<div data-pjax-container>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment