jbox-web / ajax-datatables-rails

A wrapper around DataTable's ajax methods that allow synchronization with server-side pagination in a Rails app
MIT License
585 stars 228 forks source link

def_delegator not working? #346

Closed aximuseng closed 4 years ago

aximuseng commented 4 years ago

Upgraded from '0.4.0' to the latest version. Now I get:

undefined methodlink_to' for nil:NilClass`

Basically none of my def_delegators definitions work:

def_delegators :@view, :content_tag, :link_to, :policy, :policy_scope, :action_name, :poly_parent, :controller_name, :distance_of_time

I have followed the upgrade instructions as far as I can tell. The old '0.4.0' version works fine.

Any obvious ideas?

toomanyjoes commented 4 years ago

How are you passing the view_context into your initialize method? This has been changed. Before: MyDatatable.new(view_context, my_arg1: arg1, my_arg2: arg2)

After: MyDatatable.new(params, view_context: view_context, my_arg1: arg1, my_arg2: arg2)

It's passed in as an option now, not a requirement.

aximuseng commented 4 years ago

Yup - the basic example has this listed wrong:

https://github.com/jbox-web/ajax-datatables-rails/blob/master/README.md#4-setup-the-controller-action

I just had params and no view_context. I would have never figured that out. Thanks.

defaultzero commented 4 years ago

I was having this same issue. I fixed it by adding in the following code:

  def initialize(params, opts = {})
    @view = opts[:view_context]
    super
  end

I suppose this is now required.