And the following in our some_model_datatable.rb file:
def view_columns
# Declare strings in this format: ModelName.column_name
# or in aliased_join_table.column_name format
@view_columns ||= {
number_of_people: { source: "number_of_people"}
}
end
def get_raw_records
# insert query here
Group.includes(:organization, :group_users).select("groups.*, (select count(*) from group_users where group_users.group_id = groups.id) as number_of_people")
end
It displays the following error in the console:
NoMethodError - undefined method `fetch' for nil:NilClass:
app/datatables/group_datatable.rb:25:in `data'
app/controllers/groups_controller.rb:93:in `block (2 levels) in index'
app/controllers/groups_controller.rb:92:in `index'
where in group_datatable.rb:25 there's the following code:
records.map do |record|
...
It would be nice if the error messages were a bit more descriptive, because we spent around 2-3 hours searching for the mistake, which was actually that the {data: "some_column"} value should be the same as the @view_columns key name (which is number_of_people).
Given we have the following code in our js file:
And the following in our some_model_datatable.rb file:
It displays the following error in the console:
where in group_datatable.rb:25 there's the following code:
It would be nice if the error messages were a bit more descriptive, because we spent around 2-3 hours searching for the mistake, which was actually that the {data: "some_column"} value should be the same as the @view_columns key name (which is number_of_people).