-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
undefined method `to_unsafe_h' for nil:NilClass #246
Comments
|
Thanks! That fixed the error on edit: Never mind, the error was in my view Going back to v0..3 means I need to change my Map Data to something like this?
My json result:
|
It's because prices/index.json doesn't have the column definition in the URL. The options hash contains the params from the URL and as such needs all of the column information. It didn't used to be this way, you used to be able to call the .json on the URL and just get the raw json, but now to do that you have to add the column defs to the URL. You can manually build it if you need to, note that the URL is available in the js console of the page (not for json only obviously, but for your regular datatables page request). The pieces of data that are necessary are:
The index of the columns array has to match the index of your data records array (or hash), as does the data attribute. Once you've populated the data for ALL the columns you want, open the console and run your string through URI to encode it.
You'll get something like this:
Add the encoded string to your URL (domain + path) and the json should load without error. |
I am using ajax-datatables-rails (0.4.0) and still getting same error .... I am using latest version and this version have updated code here Instead of that I am still getting same problem. |
@rajeev-khangar As @trh suggests, are you passing column definitions/options to the request? |
I have same problem here. I don't understand where I should build these definitions to be passed, and foremost why? This is just wierd and wrong imho. |
@mrudult |
@rajeev-khangar I don't think this has anything to with internet speed. |
problem exist for us as well. any solution except downgrading? |
how to fix this error? def index
respond_to do |format|
format.html
format.json { render json: CategoryDatatable.new(view_context) }
end
end
class CategoryDatatable < AjaxDatatablesRails::Base
def view_columns
# Declare strings in this format: ModelName.column_name
# or in aliased_join_table.column_name format
@view_columns ||= {
id: { source: "Category.id", cond: :eq },
name: { source: "Category.name", cond: :like }
}
end
def data
records.map do |record|
{
# example:
id: record.id,
name: record.name
}
end
end
def get_raw_records
# insert query here
Category.all
end
end
$ ->
$('#categories-datatable').dataTable
processing: true
serverSide: true
ajax: $('#categories-datatable').data('source')
pagingType: 'full_numbers'
columns: [
{data: 'id'}
{data: 'name'}
]
# pagingType is optional, if you want full pagination controls.
# Check dataTables documentation to learn more about
# available options. |
put it in the controller before calling Datatable params["columns"] ||= { "0" => {"data" => "" } }
params["length"] ||= -1 |
Problem is still going on. Anyone find a solution? |
@demir the solution of @MichaelBK works |
It's 2019 and I still see this problem. Is there any real fix for it? |
In 2019.5.29 and I use sqlite and create a model with no any records. I see this problem. |
The error occurred in
|
Had this issue .. In my case was related to link to access the page. I had a link to the data tables pages with format :json - Replacing with |
I suppose this is fixed in #315, but a new version has not been released yet |
I am getting Error 1 when trying to load the datatable view. When I visit the .json page at 'prices/index.json' I see this:
NoMethodError in PricesController#index
undefined method `to_unsafe_h' for nil:NilClass
The text was updated successfully, but these errors were encountered: