thingspeak icon indicating copy to clipboard operation
thingspeak copied to clipboard

[Delete] causes NoMethodError

Open TJuergensen opened this issue 6 years ago • 0 comments

Hello, I am pretty new to Ruby and have to fix a ThingSpeak server. The problem is, the admin account cannot delete any accounts or Channels. Neither of these errors show an application trace, only full traces

Error of Account-deletion: NoMethodError in Admin::ChannelsController#destroy undefined method `name' for nil:NilClass Full-Trace:


vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/associations/has_many_association.rb:81:in `cached_counter_attribute_name'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/associations/has_many_association.rb:104:in `inverse_updates_counter_cache?'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/associations/has_many_association.rb:114:in `delete_records'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/associations/collection_association.rb:493:in `remove_records'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/associations/collection_association.rb:486:in `block in delete_or_destroy'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/associations/collection_association.rb:152:in `block in transaction'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/transactions.rb:209:in `transaction'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/associations/collection_association.rb:151:in `transaction'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/associations/collection_association.rb:486:in `delete_or_destroy'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/associations/collection_association.rb:247:in `destroy'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/associations/collection_association.rb:170:in `destroy_all'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/associations/has_many_association.rb:26:in `handle_dependency'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/associations/builder/association.rb:97:in `has_many_dependent_for_api_keys'
vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.5/lib/active_support/callbacks.rb:377:in `_run__4271050200535634837__destroy__callbacks'
vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.5/lib/active_support/callbacks.rb:80:in `run_callbacks'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/callbacks.rb:292:in `destroy'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/transactions.rb:265:in `block in destroy'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/transactions.rb:330:in `block in with_transaction_returning_status'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/connection_adapters/abstract/database_statements.rb:221:in `within_new_transaction'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/transactions.rb:209:in `transaction'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/transactions.rb:327:in `with_transaction_returning_status'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/transactions.rb:265:in `destroy'
vendor/bundle/ruby/2.3.0/bundler/gems/active_admin-0c83cfe0b9b4/lib/active_admin/resource_controller/data_access.rb:189:in `block in destroy_resource'
vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.5/lib/active_support/core_ext/object/try.rb:45:in `public_send'
vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.5/lib/active_support/core_ext/object/try.rb:45:in `try'
vendor/bundle/ruby/2.3.0/bundler/gems/active_admin-0c83cfe0b9b4/lib/active_admin/callbacks.rb:79:in `block (2 levels) in define_active_admin_callbacks'
vendor/bundle/ruby/2.3.0/bundler/gems/active_admin-0c83cfe0b9b4/lib/active_admin/resource_controller/data_access.rb:188:in `destroy_resource'
vendor/bundle/ruby/2.3.0/gems/inherited_resources-1.4.1/lib/inherited_resources/actions.rb:58:in `destroy'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/abstract_controller/base.rb:189:in `process_action'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_controller/metal/rendering.rb:10:in `process_action'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.5/lib/active_support/callbacks.rb:493:in `_run__3531449486506308946__process_action__callbacks'
vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.5/lib/active_support/callbacks.rb:80:in `run_callbacks'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/abstract_controller/callbacks.rb:17:in `process_action'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_controller/metal/rescue.rb:29:in `process_action'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.5/lib/active_support/notifications.rb:159:in `block in instrument'
vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.5/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.5/lib/active_support/notifications.rb:159:in `instrument'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/abstract_controller/base.rb:136:in `process'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/abstract_controller/rendering.rb:44:in `process'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_controller/metal.rb:195:in `dispatch'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_controller/metal.rb:231:in `block in action'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_dispatch/routing/route_set.rb:48:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_dispatch/journey/router.rb:71:in `block in call'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_dispatch/journey/router.rb:59:in `each'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_dispatch/journey/router.rb:59:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_dispatch/routing/route_set.rb:674:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/rack/error_collector.rb:50:in `traced_call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/rack/agent_hooks.rb:26:in `traced_call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/rack/browser_monitoring.rb:23:in `traced_call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
vendor/bundle/ruby/2.3.0/gems/warden-1.2.3/lib/warden/manager.rb:35:in `block in call'
vendor/bundle/ruby/2.3.0/gems/warden-1.2.3/lib/warden/manager.rb:34:in `catch'
vendor/bundle/ruby/2.3.0/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/rack-1.5.2/lib/rack/conditionalget.rb:35:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-xml_parser-1.0.1/lib/action_dispatch/xml_params_parser.rb:16:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_dispatch/middleware/flash.rb:241:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
vendor/bundle/ruby/2.3.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_dispatch/middleware/cookies.rb:486:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/query_cache.rb:36:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.5/lib/active_support/callbacks.rb:373:in `_run__4364726816475611795__call__callbacks'
vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.5/lib/active_support/callbacks.rb:80:in `run_callbacks'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_dispatch/middleware/reloader.rb:64:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/railties-4.0.5/lib/rails/rack/logger.rb:38:in `call_app'
vendor/bundle/ruby/2.3.0/gems/railties-4.0.5/lib/rails/rack/logger.rb:20:in `block in call'
vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.5/lib/active_support/tagged_logging.rb:68:in `block in tagged'
vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.5/lib/active_support/tagged_logging.rb:26:in `tagged'
vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.5/lib/active_support/tagged_logging.rb:68:in `tagged'
vendor/bundle/ruby/2.3.0/gems/railties-4.0.5/lib/rails/rack/logger.rb:20:in `call'
vendor/bundle/ruby/2.3.0/gems/quiet_assets-1.0.3/lib/quiet_assets.rb:23:in `call_with_quiet_assets'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_dispatch/middleware/request_id.rb:21:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.5/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/rack-utf8_sanitizer-1.2.2/lib/rack/utf8_sanitizer.rb:15:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-4.0.5/lib/action_dispatch/middleware/static.rb:64:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/railties-4.0.5/lib/rails/engine.rb:511:in `call'
vendor/bundle/ruby/2.3.0/gems/railties-4.0.5/lib/rails/application.rb:97:in `call'
vendor/bundle/ruby/2.3.0/gems/railties-4.0.5/lib/rails/railtie/configurable.rb:30:in `method_missing'
vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
vendor/bundle/ruby/2.3.0/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
vendor/bundle/ruby/2.3.0/gems/puma-2.9.1/lib/puma/server.rb:490:in `handle_request'
vendor/bundle/ruby/2.3.0/gems/puma-2.9.1/lib/puma/server.rb:361:in `process_client'
vendor/bundle/ruby/2.3.0/gems/puma-2.9.1/lib/puma/server.rb:254:in `block in run'
vendor/bundle/ruby/2.3.0/gems/puma-2.9.1/lib/puma/thread_pool.rb:92:in `block in spawn_thread'

Request

Parameters:

{"_method"=>"delete",
 "authenticity_token"=>"mVLFQMTJRvdazg6BpsFs1FTirLJhodqHxwZsaeYrEFI=",
 "id"=>"5" 

Response

Headers:
None

As for the channel-deletion, its the same as Issue #52 , except for the fact, that there is no application Trace shown.

admin-user routing:

admin_user                         
GET        /admin/users/:id(.:format)                                  admin/users#show 
PATCH      /admin/users/:id(.:format)                                  admin/users#update
PUT        /admin/users/:id(.:format)                                  admin/users#update
DELETE     /admin/users/:id(.:format)                                  admin/users#destroy

Each user can delete their own account without problem, just the admin account cannot do that.

app/controlers/users_controller.rb (pastebin) (used pastebin due to long file)

app/admin/user.rb

ctiveAdmin.register User do
  require 'csv'

  filter :email
  filter :login
  filter :created_at

  permit_params :email, :login, :bio, :website

  index do
    column :id
    column :email
    column :login
    column :created_at
    actions
  end

  show do
    attributes_table do
      rows :id, :email, :login, :time_zone, :bio, :website, :created_at, :sign_in_count, :current_sign_in_at, :last_sign_in_at, :current_sign_in_ip, :last_sign_in_ip
    end
    panel 'Channels' do
      table_for user.channels do
        column :id
        column(:name) { |channel| link_to channel.name, channel }
      end
    end
  end

  form do |f|
    f.semantic_errors *f.object.errors.keys
    f.inputs :email, :login
    f.actions
  end

  # custom action for signups per day
  collection_action :signups, :method => :get, :format => :csv do
    @csv_headers = [:day, :signups]
    @days = User.signups_per_day
  end

  # custom action for emails list
  collection_action :emails, :method => :get do
    @users = User.all
  end

end

I don't know which other info is important, feel free to ask if anything else is needed.

Does anyone have a clue how to fix this? Thanks in advice

TJ

TJuergensen avatar Jun 06 '18 09:06 TJuergensen