Skip to content

Latest commit

 

History

History
53 lines (39 loc) · 1.67 KB

migrate.md

File metadata and controls

53 lines (39 loc) · 1.67 KB

To migrate from v0.4.x to v1.0.0

  1. To mitigate the first change (Datatables no longer inherits from AjaxDatatablesRails::Base but from AjaxDatatablesRails::ActiveRecord)

Create a new ApplicationDatatable class and make all your classes inherits from it :

class ApplicationDatatable < AjaxDatatablesRails::ActiveRecord
end

class PostDatatable < ApplicationDatatable
end

Note : This is now in the ProTips™ section of the documentation.

  1. To mitigate the second change (The view_context is no longer injected in Datatables)

Update the ApplicationDatatable class :

class ApplicationDatatable < AjaxDatatablesRails::ActiveRecord
  extend Forwardable
  attr_reader :view
  def initialize(params, opts = {})
    @view = opts[:view_context]
    super
  end
end

and update your controllers :

# before
respond_to do |format|
  format.json { render json: UserDatatable.new(view_context) }
end

# after
respond_to do |format|
  format.json { render json: UserDatatable.new(params, view_context: view_context) }
end

# if you need to inject some options
respond_to do |format|
  format.json { render json: UserDatatable.new(params, view_context: view_context, my: 'options') }
end

This way, you can still use def_delegators in your datatables as in the documentation.

Note that the recommanded way is to use Draper gem to separate filtering logic from view/presentation logic as in the documentation.