gryphon / simple_datatables

Simple Datatables.net integration for rails 3
MIT License
60 stars 40 forks source link

support decent_exposure #5

Closed linojon closed 12 years ago

linojon commented 12 years ago

hi, when i write my #search controller action as your examples, its ok

def search
    @people = Person.search(params[:search]).paginate(:page => params[:page], :per_page=>params[:per_page])
    respond_with @people, :locals => { :collection => @people }
end

But not when i use the decent_exposure gem,

expose(:people) { Person.search(params[:search]).paginate(:page => (params[:page] || 1), :per_page=>params[:per_page]) }
expose(:person)

def search
  respond_with people, :locals => {:collection => people}
end

Looking inside application.datatables.jsonify, the first way gets instance_variables

[:@_config, :@view_renderer, :@_routes, :@people, :@_assigns, :@_controller, :@_request, :@view_flow, :@output_buffer, :@virtual_path]

but with decent_exposure, the instance_variables are

[:@_config, :@view_renderer, :@_routes, :@_resources, :@_assigns, :@_controller, :@_request, :@view_flow, :@output_buffer, :@virtual_path]

But @_resources.class is a Hash, like { :people => [array of people] } not an active relation, and never equals collection.

gryphon commented 12 years ago

Please check the current version. You may set the collection or pagination counters manually.