Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `read_attribute_for_serialization' for #XXXDataTable #344

Open
bipashant opened this issue Oct 11, 2019 · 0 comments
Open

Comments

@bipashant
Copy link

Hi
I've followed the documentation step by step but getting the above error while rendering the JSON.

Ruby 2.3.1
Rails 4.2.1
gem 'active_model_serializers', '~> 0.10.10'

Here is my datatable class

class SamsaraTripDatatable < AjaxDatatablesRails::ActiveRecord

  def view_columns
    @view_columns ||= {
      start_at: { source: "SamsaraTrip.start_at", cond: :date_range, delimiter: '-yadcf_delim-'},
      start_location: { source: "SamsaraTrip.start_location", cond: :like, searchable: true, orderable: true  }
    }
  end

  def data
    records.map do |record|
      {
        start_at: record.start_at,
        start_location: record.start_location
        DT_RowId:   record.id
      }
    end
  end

  def get_raw_records
    SamsaraTrip.all
  end

end

Here is my backtrace.

NoMethodError at /samsara_trips.json
====================================

> undefined method `read_attribute_for_serialization' for #<SamsaraTripDatatable:0x007fbee6a00580>

app/controllers/samsara_trips_controller.rb, line 8
---------------------------------------------------

``` ruby
    3     before_action -> { authorize Feature.find_by_key('drivers'), :access? }
    4   
    5     def index
    6       respond_to do |format|
    7         format.html
>   8         format.json { render json: SamsaraTripDatatable.new(params) }
    9       end
   10     end
   11   
   12   end

App backtrace
-------------

 - app/controllers/samsara_trips_controller.rb:8:in `block (2 levels) in index'
 - app/controllers/samsara_trips_controller.rb:6:in `index'
 - app/middleware/my_custom_elevator.rb:10:in `call'

Full backtrace
--------------

 - active_model_serializers (0.10.10) lib/active_model/serializer.rb:397:in `read_attribute_for_serialization'
 - active_model_serializers (0.10.10) lib/active_model_serializers/adapter/json_api/resource_identifier.rb:63:in `id_for'
 - active_model_serializers (0.10.10) lib/active_model_serializers/adapter/json_api/resource_identifier.rb:39:in `initialize'
 - active_model_serializers (0.10.10) lib/active_model_serializers/adapter/json_api.rb:249:in `process_resource'
 - active_model_serializers (0.10.10) lib/active_model_serializers/adapter/json_api.rb:242:in `block in resource_objects_for'
 - active_model_serializers (0.10.10) lib/active_model_serializers/adapter/json_api.rb:242:in `resource_objects_for'
 - active_model_serializers (0.10.10) lib/active_model_serializers/adapter/json_api.rb:94:in `success_document'
 - active_model_serializers (0.10.10) lib/active_model_serializers/adapter/json_api.rb:63:in `serializable_hash'
 - active_model_serializers (0.10.10) lib/active_model_serializers/adapter/base.rb:61:in `as_json'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/json/encoding.rb:34:in `encode'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/json/encoding.rb:21:in `encode'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/core_ext/object/json.rb:37:in `to_json_with_active_support_encoder'
 - active_model_serializers (0.10.10) lib/active_model_serializers/serializable_resource.rb:10:in `to_json'
 - active_model_serializers (0.10.10) lib/active_model_serializers/logging.rb:71:in `block (3 levels) in notify'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:117:in `call'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:505:in `call'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:498:in `block (2 levels) in around'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:343:in `block (2 levels) in simple'
 - active_model_serializers (0.10.10) lib/active_model_serializers/logging.rb:24:in `block (3 levels) in instrument_rendering'
 - active_model_serializers (0.10.10) lib/active_model_serializers/logging.rb:81:in `block in notify_render'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/notifications.rb:164:in `block in instrument'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/notifications.rb:164:in `instrument'
 - active_model_serializers (0.10.10) lib/active_model_serializers/logging.rb:80:in `notify_render'
 - active_model_serializers (0.10.10) lib/active_model_serializers/logging.rb:23:in `block (2 levels) in instrument_rendering'
 - active_model_serializers (0.10.10) lib/active_model_serializers/logging.rb:97:in `block in tag_logger'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/tagged_logging.rb:68:in `block in tagged'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/tagged_logging.rb:26:in `tagged'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/tagged_logging.rb:68:in `tagged'
 - active_model_serializers (0.10.10) lib/active_model_serializers/logging.rb:97:in `tag_logger'
 - active_model_serializers (0.10.10) lib/active_model_serializers/logging.rb:22:in `block in instrument_rendering'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:441:in `block in make_lambda'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:342:in `block in simple'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:497:in `block in around'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:505:in `call'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:92:in `_run_callbacks'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:776:in `_run_render_callbacks'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:81:in `run_callbacks'
 - active_model_serializers (0.10.10) lib/active_model_serializers/logging.rb:70:in `block (2 levels) in notify'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/action_controller/metal/renderers.rb:116:in `block in <module:Renderers>'
 - active_model_serializers (0.10.10) lib/action_controller/serialization.rb:72:in `block (2 levels) in <module:Serialization>'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/action_controller/metal/renderers.rb:45:in `block in _render_to_body_with_renderer'
 - /Users/bishant/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/set.rb:283:in `each'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/action_controller/metal/renderers.rb:41:in `_render_to_body_with_renderer'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/action_controller/metal/renderers.rb:37:in `render_to_body'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/abstract_controller/rendering.rb:25:in `render'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/action_controller/metal/rendering.rb:16:in `render'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
 - /Users/bishant/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/core_ext/benchmark.rb:12:in `ms'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/action_controller/metal/instrumentation.rb:44:in `block in render'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activerecord/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/action_controller/metal/instrumentation.rb:43:in `render'
 - app/controllers/samsara_trips_controller.rb:8:in `block (2 levels) in index'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/action_controller/metal/mime_responds.rb:215:in `respond_to'
 - app/controllers/samsara_trips_controller.rb:6:in `index'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/abstract_controller/base.rb:198:in `process_action'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/action_controller/metal/rendering.rb:10:in `process_action'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:117:in `call'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:505:in `call'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:498:in `block (2 levels) in around'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:313:in `block (2 levels) in halting'
 - react-rails (2.4.7) lib/react/rails/controller_lifecycle.rb:31:in `use_react_component_helper'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:432:in `block in make_lambda'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:312:in `block in halting'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:497:in `block in around'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:505:in `call'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:92:in `_run_callbacks'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:776:in `_run_process_action_callbacks'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/callbacks.rb:81:in `run_callbacks'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/abstract_controller/callbacks.rb:19:in `process_action'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/action_controller/metal/rescue.rb:29:in `process_action'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/notifications.rb:164:in `block in instrument'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activesupport/lib/active_support/notifications.rb:164:in `instrument'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/activerecord/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionpack/lib/abstract_controller/base.rb:137:in `process'
 -  () Users/bishant/.rvm/gems/ruby-2.2.3/bundler/gems/rails-c0e1e4a069b3/actionview/lib/action_view/rendering.rb:30:in `process'
 - rack-mini-profiler (1.0.0) lib/mini_profiler/profiling_methods.rb:104:in `block in profile_method'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant