-
Notifications
You must be signed in to change notification settings - Fork 227
Closed
Description
Hi,
I'm trying to use your gem with my project. I had install "jquery-datatable-rails" gem and I need to add to the query through AJAX. My model is "Establecimiento".
My code
establecimiento_datatable.rb
class EstablecimientoDatatable < AjaxDatatablesRails::Base
include AjaxDatatablesRails::Extensions::Kaminari
def sortable_columns
# list columns inside the Array in string dot notation.
# Example: 'users.email'
@sortable_columns ||= ['establecimientos.cue']
end
def searchable_columns
# list columns inside the Array in string dot notation.
# Example: 'users.email'
@searchable_columns ||= []
end
private
def data
records.map do |record|
[
record.cue
]
end
end
def get_raw_records
Establecimiento.all
end
endestablecimientos_controller.rb
def index
@establecimientos = EstablecimientoDatatable.new(view_context)
respond_to do |format|
format.html
format.json { render json: @establecimientos }
end
endindex.html.erb
<div class="table-responsive">
<table id="tabla-establecimiento" class="table table-striped table-bordered table-hover" data-source="<%= establecimientos_path(format: :json) %>">
<thead>
<tr>
<th>Cue</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<script type="text/javascript">
$(document).ready(function($) {
$('#tabla-establecimiento').dataTable({
"oLanguage": {"sUrl": "assets/language.es.json",},
"processing": true,
"serverSide": true,
"sAjaxSource": $('#tabla-establecimiento').data('source')
});
});
</script>Error
undefined method `[]' for nil:NilClass
app/datatables/establecimiento_datatable.rb:23:in `data'
app/controllers/establecimientos_controller.rb:10:in `block (2 levels) in index'
app/controllers/establecimientos_controller.rb:8:in `index'
I search in google for many sites and didnt get any solution for this error, hope you can help me and very good job with this project.
Sorry for my english, Greetings from Argentina!!
Metadata
Metadata
Assignees
Labels
No labels