Skip to content

Instantly share code, notes, and snippets.

@Trilarion
Created January 6, 2022 19:45
Show Gist options
  • Save Trilarion/759cd28877179b28f9a387d400d47294 to your computer and use it in GitHub Desktop.
Save Trilarion/759cd28877179b28f9a387d400d47294 to your computer and use it in GitHub Desktop.
Question post on collab.codidact.org that is blocked by cloudfare
title of question: How to fix 500 Server Error "NoMethodError: undefined method `id' for nil:NilClass"?
tags: support, installation
body content:
Following the [set up guide](https://collab.codidact.org/posts/280451/280452#answer-280452) I was able to start rails server and got my very first QPixel page served (see screenshot):
![Screenshot of the 500 Server Error](https://collab.codidact.org/uploads/nTMMK32Yu5C8JtMYJYxaUbEN)
Unfortunately it was a `500 Server Error`, which I did not expect and which wasn't mentioned in the guide. Attached is part of the console output which speaks of a `NoMethodError (undefined method `id' for nil:NilClass)`.
```
Started GET "/" for 127.0.0.1 at 2022-01-06 09:55:55 +0100
(1.6ms) SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
(4.3ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
Processing by CategoriesController#homepage as HTML
/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activemodel-5.2.6/lib/active_model/type/integer.rb:13: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activemodel-5.2.6/lib/active_model/type/value.rb:8: warning: The called method `initialize' is defined here
/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activerecord-5.2.6/lib/active_record/connection_adapters/mysql/database_statements.rb:12: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activerecord-5.2.6/lib/active_record/connection_adapters/abstract/query_cache.rb:95: warning: The called method `select_all' is defined here
Community Load (20.8ms) SELECT `communities`.* FROM `communities` WHERE `communities`.`host` = 'localhost:3000' LIMIT 1
Host localhost:3000, community #1 (Dev Community)
User Load (9.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activerecord-5.2.6/lib/active_record/relation/delegation.rb:132: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activerecord-5.2.6/lib/active_record/relation.rb:25: warning: The called method `initialize' is defined here
CommunityUser Load (1.5ms) SELECT `community_users`.* FROM `community_users` WHERE `community_users`.`user_id` = 1 AND `community_users`.`community_id` = 1 LIMIT 1
User 1 (aaa) signed in
/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activerecord-5.2.6/lib/active_record/associations.rb:1855: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activerecord-5.2.6/lib/active_record/associations.rb:1368: warning: The called method `has_many' is defined here
PostType Load (2.4ms) SELECT `post_types`.* FROM `post_types` ORDER BY `post_types`.`id` ASC LIMIT 1000
(3.1ms) SELECT COUNT(*) FROM `flags` WHERE `flags`.`community_id` = 1 AND `flags`.`status` IS NULL
ModWarning Exists (1.3ms) SELECT 1 AS one FROM `warnings` WHERE `warnings`.`community_user_id` = 1 AND `warnings`.`active` = TRUE LIMIT 1
Category Load (1.6ms) SELECT `categories`.* FROM `categories` WHERE `categories`.`community_id` = 1 AND `categories`.`is_homepage` = TRUE ORDER BY `categories`.`id` ASC LIMIT 1
Completed 500 Internal Server Error in 199ms (ActiveRecord: 66.8ms)
NoMethodError (undefined method `id' for nil:NilClass):
app/controllers/categories_controller.rb:171:in `update_last_visit'
app/controllers/categories_controller.rb:24:in `homepage'
Processing by ErrorsController#error as HTML
Host localhost:3000, community #1 (Dev Community)
User 1 (aaa) signed in
CACHE (0.0ms) SELECT COUNT(*) FROM `flags` WHERE `flags`.`community_id` = 1 AND `flags`.`status` IS NULL
CACHE ModWarning Exists (0.0ms) SELECT 1 AS one FROM `warnings` WHERE `warnings`.`community_user_id` = 1 AND `warnings`.`active` = TRUE LIMIT 1
/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activerecord-5.2.6/lib/active_record/transactions.rb:212: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activerecord-5.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:260: warning: The called method `transaction' is defined here
/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activerecord-5.2.6/lib/active_record/connection_adapters/abstract/transaction.rb:171: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activerecord-5.2.6/lib/active_record/connection_adapters/abstract/transaction.rb:97: warning: The called method `initialize' is defined here
(0.6ms) BEGIN
ErrorLog Create (3.9ms) INSERT INTO `error_logs` (`community_id`, `user_id`, `klass`, `message`, `backtrace`, `request_uri`, `host`, `created_at`, `updated_at`, `uuid`, `user_agent`) VALUES (1, 1, 'NoMethodError', 'undefined method `id\' for nil:NilClass', '/home/abanta/qpixel/app/controllers/categories_controller.rb:171:in `update_last_visit\'\n/home/abanta/qpixel/app/controllers/categories_controller.rb:24:in `homepage\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/abstract_controller/base.rb:194:in `process_action\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_controller/metal/rendering.rb:30:in `process_action\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/abstract_controller/callbacks.rb:42:in `block in process_action\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.6/lib/active_support/callbacks.rb:132:in `run_callbacks\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/abstract_controller/callbacks.rb:41:in `process_action\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_controller/metal/rescue.rb:22:in `process_action\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_controller/metal/instrumentation.rb:34:in `block in process_action\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.6/lib/active_support/notifications.rb:168:in `block in instrument\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.6/lib/active_support/notifications/instrumenter.rb:23:in `instrument\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.6/lib/active_support/notifications.rb:168:in `instrument\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_controller/metal/instrumentation.rb:32:in `process_action\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_controller/metal/params_wrapper.rb:256:in `process_action\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activerecord-5.2.6/lib/active_record/railties/controller_runtime.rb:24:in `process_action\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/abstract_controller/base.rb:134:in `process\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionview-5.2.6/lib/action_view/rendering.rb:32:in `process\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_controller/metal.rb:191:in `dispatch\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_controller/metal.rb:252:in `dispatch\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/routing/route_set.rb:52:in `dispatch\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/routing/route_set.rb:34:in `serve\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/journey/router.rb:52:in `block in serve\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/journey/router.rb:35:in `each\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/journey/router.rb:35:in `serve\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/routing/route_set.rb:840:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/warden-1.2.9/lib/warden/manager.rb:36:in `block in call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/warden-1.2.9/lib/warden/manager.rb:34:in `catch\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/warden-1.2.9/lib/warden/manager.rb:34:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/tempfile_reaper.rb:15:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/etag.rb:27:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/conditional_get.rb:27:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/head.rb:12:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/http/content_security_policy.rb:18:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:266:in `context\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:260:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/middleware/cookies.rb:670:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activerecord-5.2.6/lib/active_record/migration.rb:559:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.6/lib/active_support/callbacks.rb:98:in `run_callbacks\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/middleware/callbacks.rb:26:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/middleware/executor.rb:14:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:135:in `call_app\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:30:in `block in call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:20:in `catch\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:20:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/railties-5.2.6/lib/rails/rack/logger.rb:38:in `call_app\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/railties-5.2.6/lib/rails/rack/logger.rb:26:in `block in call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.6/lib/active_support/tagged_logging.rb:71:in `block in tagged\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.6/lib/active_support/tagged_logging.rb:28:in `tagged\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.6/lib/active_support/tagged_logging.rb:71:in `tagged\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/railties-5.2.6/lib/rails/rack/logger.rb:26:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/middleware/remote_ip.rb:81:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/middleware/request_id.rb:27:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/method_override.rb:24:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/runtime.rb:22:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.6/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/middleware/executor.rb:14:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.6/lib/action_dispatch/middleware/static.rb:127:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/rack-mini-profiler-2.3.2/lib/mini_profiler/profiler.rb:384:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/railties-5.2.6/lib/rails/engine.rb:524:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/puma-4.3.10/lib/puma/configuration.rb:228:in `call\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/puma-4.3.10/lib/puma/server.rb:718:in `handle_request\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/puma-4.3.10/lib/puma/server.rb:472:in `process_client\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/puma-4.3.10/lib/puma/server.rb:328:in `block in run\'\n/home/abanta/qpixel/vendor/bundle/ruby/2.7.0/gems/puma-4.3.10/lib/puma/thread_pool.rb:134:in `block in spawn_thread\'', 'http://localhost:3000/', 'localhost:3000', '2022-01-06 08:55:56', '2022-01-06 08:55:56', 'a376286a-d0c0-4cc0-8532-16c8f630b2ca', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0')
(3.7ms) COMMIT
Rendering errors/internal_server_error.html.erb within layouts/without_sidebar
Rendered errors/internal_server_error.html.erb within layouts/without_sidebar (1.4ms)
SiteSetting Load (1.5ms) SELECT `site_settings`.* FROM `site_settings` WHERE (`site_settings`.`community_id` = 1 OR `site_settings`.`community_id` IS NULL) AND `site_settings`.`name` = 'IconPath' ORDER BY IF(site_settings.community_id IS NULL, 1, 0) LIMIT 1
Rendered layouts/_head.html.erb (359.5ms)
SiteSetting Load (0.9ms) SELECT `site_settings`.* FROM `site_settings` WHERE (`site_settings`.`community_id` = 1 OR `site_settings`.`community_id` IS NULL) AND `site_settings`.`name` = 'MobileLogoPath' ORDER BY IF(site_settings.community_id IS NULL, 1, 0) LIMIT 1
(1.1ms) SELECT COUNT(*) FROM `notifications` WHERE `notifications`.`user_id` = 1 AND `notifications`.`is_read` = FALSE
ActiveStorage::Attachment Load (1.7ms) SELECT `active_storage_attachments`.* FROM `active_storage_attachments` WHERE `active_storage_attachments`.`record_id` = 1 AND `active_storage_attachments`.`record_type` = 'User' AND `active_storage_attachments`.`name` = 'avatar' LIMIT 1
Community Load (0.8ms) SELECT `communities`.* FROM `communities` WHERE `communities`.`is_fake` = FALSE
Community Load (0.8ms) SELECT `communities`.* FROM `communities` WHERE `communities`.`is_fake` = FALSE AND `communities`.`hidden` = FALSE
Category Load (0.9ms) SELECT `categories`.* FROM `categories` WHERE `categories`.`community_id` = 1 ORDER BY `categories`.`sequence` ASC, `categories`.`id` ASC
Rendered layouts/_header.html.erb (26.4ms)
Rendered layouts/_footer.html.erb (0.6ms)
SiteSetting Load (0.8ms) SELECT `site_settings`.* FROM `site_settings` WHERE (`site_settings`.`community_id` = 1 OR `site_settings`.`community_id` IS NULL) AND `site_settings`.`name` = 'AnalyticsURL' ORDER BY IF(site_settings.community_id IS NULL, 1, 0) LIMIT 1
Rendered layouts/_matomo.html.erb (3.0ms)
Completed 500 Internal Server Error in 429ms (Views: 382.4ms | ActiveRecord: 25.4ms)
...
Completed 500 Internal Server Error in 360ms (Views: 204.1ms | ActiveRecord: 26.5ms)
```
Is this intended behavior or a bug (and if so how to fix it)?
I tried to continue with the guide and signed up a user, but that didn't change anything about the error. It seems like the dev community is not set up correctly.
In trying to reach this point I repeated steps of the manual several times (and encountered other errors), so maybe I compromised the state of the installation somewhere. I will repeat the guide on a clean system again to be sure. Nevertheless this question should remain as something that might happen to others as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment