Skip to content

Commit 31cd706

Browse files
committed
Update README
1 parent 850fdae commit 31cd706

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ All the datatable customizations (header, tr, td, css classes, width, height, bu
3939
jQuery DataTables is a very powerful tool with a lot of customizations available. Take the time to [read the doc](https://datatables.net/reference/option/).
4040

4141

42-
## Warning
42+
## Warnings
43+
44+
**Breaking changes :** the *v1.0.0* version is a **major break** from *v0.4*.
45+
46+
* Datatables no longer inherits from `AjaxDatatablesRails::Base` but from `AjaxDatatablesRails::ActiveRecord` (this solves [#228](https://github.com/jbox-web/ajax-datatables-rails/issues/228))
47+
* The `view_context` is no longer injected in Datatables but only the `params` hash (see the [example](#4-setup-the-controller-action)). This will break calls to helpers methods.
48+
49+
To mitigate this 2 changes see the [migration doc](/doc/migrate.md).
4350

4451
**Breaking changes :** the *v0.4* version is a **major break** from *v0.3*.
4552

doc/migrate.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## To migrate from `v0.4.x` to `v1.0.0`
2+
3+
1) To mitigate the first change (Datatables no longer inherits from `AjaxDatatablesRails::Base` but from `AjaxDatatablesRails::ActiveRecord`)
4+
5+
Create a new `ApplicationDatatable` class and make all your classes inherits from it :
6+
7+
```ruby
8+
class ApplicationDatatable < AjaxDatatablesRails::ActiveRecord
9+
end
10+
11+
class PostDatatable < ApplicationDatatable
12+
end
13+
```
14+
15+
2) To mitigate the second change (The `view_context` is no longer injected in Datatables)
16+
17+
Update the `ApplicationDatatable` class :
18+
19+
```ruby
20+
class ApplicationDatatable < AjaxDatatablesRails::ActiveRecord
21+
extend Forwardable
22+
attr_reader :view
23+
def initialize(params, opts = {})
24+
@view = opts[:view_context]
25+
super
26+
end
27+
end
28+
```
29+
30+
and update your controllers :
31+
32+
```ruby
33+
respond_to do |format|
34+
format.json { render json: UserDatatable.new(params, view_context: view_context) }
35+
end
36+
```
37+
38+
This way, you can still use `def_delegators` in your datatables [as in the documentation](https://github.com/jbox-web/ajax-datatables-rails#using-view-helpers).
39+
40+
Note that the recommanded way is to use [Draper gem](https://github.com/drapergem/draper) to separate filtering logic from view/presentation logic [as in the documentation](https://github.com/jbox-web/ajax-datatables-rails#using-view-decorators).

0 commit comments

Comments
 (0)