GithubHelp home page GithubHelp logo

pjax_rails's Introduction

PJAX for Rails 3.1+

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

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

//=require pjax

All links that match $('a:not([data-remote]):not([data-behavior]):not([data-skip-pjax])') will then use PJAX.

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>

FIXME: Currently the layout is hardcoded to "application". Need to delegate that to the specific layout of the controller.

Examples for redirect_pjax_to

class ProjectsController < ApplicationController
  before_filter :set_project, except: [ :index, :create ]

  def index
    @projects = current_user.projects
  end

  def show
  end

  def create
    @project = Project.create params[:project]
    redirect_pjax_to :show, @project
  end

  def update
    @project.update_attributes params[:project]
    redirect_pjax_to :show, @project
  end

  def destroy
    @project.destroy

    index # set the objects needed for rendering index
    redirect_pjax_to :index
  end

  private
    def set_project
      @project = current_user.projects.find params[:id].to_i
    end
end

pjax_rails's People

Contributors

dhh avatar theempty avatar ianterrell avatar joliss avatar fxn avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.