page markup: • layout • external scripts and css files • page content A POST action send data and receive response as a new HTML page => full rendering on every action
{}) super({only: [:id, :name]}.merge!(options)) end end class ModelsController < ApplicationController def show model = Model.find(params[:id]) render json: model end end Easy for simple data/message transfer Did not scale (multiple output format...) Models should not be responsible of their presentation
< ActiveRecord::Base end json.(@model, :id, :name) json.other @model.compute_something class ModelsController < ApplicationController def show @model = Model.find(params[:id]) end end We use templates like we do for html rendering Partial templates Multiple presentation for models, depending of the action Advanced rendering
< ApplicationController def show @model = Model.find(params[:id]) render layout: false if request.headers['X-PJAX'] end end Simple jquery extension Reload only portions of web pages on navigation PushState support You keep the control on how links are rendered <a href='/explore' data-pjax='#main'>Explore</a> <script type="text/javascript"> $(document).pjax('a[data-pjax]'); </scrript>
with a javascript based application. Similar to PJAX with differences: • A rails project (part of Rails 4) • Replace the entire body and the title tag content • Not dependant on jQuery • Used by default for all internal links