Trying to sort by ActiveStorage field results in NameError
rakvium opened this issue · 1 comments
rakvium commented
Reproduction steps
- have a rails application with rails admin installed and mounted:
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
- create a model, for example,
rails generate model Game name:string; rails db:migrate
- add Active Storage field to it:
class Game < ApplicationRecord
has_one_attached :icon
end
- run the web server
- open Rails Admin index page for this model and try to sort by ActiveStorage field (or just go to
/admin/game?model_name=game&sort=icon
on the web server)
Expected behavior
List of model entries, with entries that have an icon sorted to be on the top.
Additional context
rails
version: 7.0.4.1rails_admin
version: 3.1.2rails_admin
npm package version: N/A (sprockets used)- full stack trace (if there's an exception)
Started GET "/admin/game?model_name=game&sort=icon" for 172.18.0.1 at 2024-03-17 14:27:15 +0000
Processing by RailsAdmin::MainController#index as HTML
Parameters: {"model_name"=>"game", "sort"=>"icon"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 2], ["LIMIT", 1]]
↳ config/initializers/rails_admin.rb:10:in `block (2 levels) in <main>'
Completed 500 Internal Server Error in 6ms (ActiveRecord: 0.2ms | Allocations: 5106)
NameError (undefined local variable or method `association' for #<RailsAdmin::Config::Fields::Types::ActiveStorage[icon] @parent=RailsAdmin::Config::Sections::Base, @root=RailsAdmin::Config::Model, @abstract_model=#<RailsAdmin::AbstractModel:0x00007f32a33022a8 @model_name="Game", @adapter=:active_record>, @defined=false, @name=:icon, @order=0, @properties=#<RailsAdmin::Adapters::ActiveRecord::Association:0x00007f32a2c63168 @association=#<ActiveRecord::Reflection::HasOneReflection:0x00007f32d9a0d238 @name=:icon_attachment, @scope=#<Proc:0x00007f32d9a0d288 /usr/local/bundle/gems/activerecord-7.0.4.1/lib/active_record/associations/builder/association.rb:55>, @options={:class_name=>"ActiveStorage::Attachment", :as=>:record, :inverse_of=>:record, :dependent=>:destroy, :strict_loading=>false}, @active_record=Game(id: integer, name: string, position: integer, created_at: datetime, updated_at: datetime, game_type: string, display_type: string, price: integer), @klass=ActiveStorage::Attachment(id: integer, name: string, record_type: string, record_id: integer, blob_id: integer, created_at: datetime), @plural_name="icon_attachments", @type="record_type", @foreign_key="record_id", @class_name="ActiveStorage::Attachment", @inverse_name=:record, @inverse_of=#<ActiveRecord::Reflection::BelongsToReflection:0x00007f32d9d347b8 @name=:record, @scope=nil, @options={:polymorphic=>true, :touch=>true}, @active_record=ActiveStorage::Attachment(id: integer, name: string, record_type: string, record_id: integer, blob_id: integer, created_at: datetime), @klass=nil, @plural_name="records", @foreign_key="record_id", @foreign_type="record_type", @counter_cache_column=nil>, @active_record_primary_key="id">, @model=Game(id: integer, name: string, position: integer, created_at: datetime, updated_at: datetime, game_type: string, display_type: string, price: integer)>, @section=RailsAdmin::Config::Sections::List, @children_fields_registered=Array>
elsif association # use column on target table
^^^^^^^^^^^
Did you mean? association?):
[rails_admin (3.1.2) lib/rails_admin/config/fields/base.rb:70:in `sort_column'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[rails_admin (3.1.2) app/controllers/rails_admin/main_controller.rb:71:in `get_sort_hash'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[rails_admin (3.1.2) app/controllers/rails_admin/main_controller.rb:131:in `get_collection'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[rails_admin (3.1.2) app/controllers/rails_admin/main_controller.rb:21:in `list_entries'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[rails_admin (3.1.2) lib/rails_admin/config/actions/index.rb:35:in `block (2 levels) in <class:Index>'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[rails_admin (3.1.2) app/controllers/rails_admin/main_controller.rb:38:in `instance_eval'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[rails_admin (3.1.2) app/controllers/rails_admin/main_controller.rb:38:in `action_missing'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/abstract_controller/base.rb:229:in `_handle_action_missing'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/abstract_controller/base.rb:215:in `process_action'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_controller/metal/rendering.rb:53:in `process_action'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/abstract_controller/callbacks.rb:234:in `block in process_action'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[activesupport (7.0.4.1) lib/active_support/callbacks.rb:118:in `block in run_callbacks'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actiontext (7.0.4.1) lib/action_text/rendering.rb:20:in `with_renderer'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actiontext (7.0.4.1) lib/action_text/engine.rb:69:in `block (4 levels) in <class:Engine>'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[activesupport (7.0.4.1) lib/active_support/callbacks.rb:127:in `instance_exec'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[activesupport (7.0.4.1) lib/active_support/callbacks.rb:127:in `block in run_callbacks'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[activesupport (7.0.4.1) lib/active_support/callbacks.rb:138:in `run_callbacks'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/abstract_controller/callbacks.rb:233:in `process_action'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_controller/metal/rescue.rb:22:in `process_action'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_controller/metal/instrumentation.rb:67:in `block in process_action'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[activesupport (7.0.4.1) lib/active_support/notifications.rb:206:in `block in instrument'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[activesupport (7.0.4.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[activesupport (7.0.4.1) lib/active_support/notifications.rb:206:in `instrument'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_controller/metal/instrumentation.rb:66:in `process_action'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_controller/metal/params_wrapper.rb:259:in `process_action'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[activerecord (7.0.4.1) lib/active_record/railties/controller_runtime.rb:27:in `process_action'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/abstract_controller/base.rb:151:in `process'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionview (7.0.4.1) lib/action_view/rendering.rb:39:in `process'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_controller/metal.rb:188:in `dispatch'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_controller/metal.rb:251:in `dispatch'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/routing/route_set.rb:32:in `serve'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/journey/router.rb:50:in `block in serve'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/journey/router.rb:32:in `each'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/journey/router.rb:32:in `serve'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/routing/route_set.rb:852:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[railties (7.0.4.1) lib/rails/engine.rb:530:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[railties (7.0.4.1) lib/rails/railtie.rb:226:in `public_send'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[railties (7.0.4.1) lib/rails/railtie.rb:226:in `method_missing'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/routing/mapper.rb:19:in `block in <class:Constraints>'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/routing/mapper.rb:48:in `serve'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/journey/router.rb:50:in `block in serve'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/journey/router.rb:32:in `each'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/journey/router.rb:32:in `serve'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/routing/route_set.rb:852:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[omniauth (2.1.1) lib/omniauth/strategy.rb:202:in `call!'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[omniauth (2.1.1) lib/omniauth/strategy.rb:169:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[omniauth (2.1.1) lib/omniauth/strategy.rb:202:in `call!'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[omniauth (2.1.1) lib/omniauth/strategy.rb:169:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[bullet (7.0.7) lib/bullet/rack.rb:17:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[cypress-on-rails (1.13.1) lib/cypress_on_rails/middleware.rb:22:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[warden (1.2.9) lib/warden/manager.rb:36:in `block in call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[warden (1.2.9) lib/warden/manager.rb:34:in `catch'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[warden (1.2.9) lib/warden/manager.rb:34:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[rack (2.2.6.2) lib/rack/tempfile_reaper.rb:15:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[rack (2.2.6.2) lib/rack/etag.rb:27:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[rack (2.2.6.2) lib/rack/conditional_get.rb:27:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[rack (2.2.6.2) lib/rack/head.rb:12:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/http/permissions_policy.rb:38:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/http/content_security_policy.rb:36:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[rack (2.2.6.2) lib/rack/session/abstract/id.rb:266:in `context'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[rack (2.2.6.2) lib/rack/session/abstract/id.rb:260:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/middleware/cookies.rb:704:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[activerecord (7.0.4.1) lib/active_record/migration.rb:603:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[activesupport (7.0.4.1) lib/active_support/callbacks.rb:99:in `run_callbacks'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/middleware/executor.rb:14:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/middleware/debug_exceptions.rb:28:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[web-console (4.2.0) lib/web_console/middleware.rb:132:in `call_app'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[web-console (4.2.0) lib/web_console/middleware.rb:28:in `block in call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[web-console (4.2.0) lib/web_console/middleware.rb:17:in `catch'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[web-console (4.2.0) lib/web_console/middleware.rb:17:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/middleware/show_exceptions.rb:26:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[railties (7.0.4.1) lib/rails/rack/logger.rb:40:in `call_app'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[railties (7.0.4.1) lib/rails/rack/logger.rb:25:in `block in call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[activesupport (7.0.4.1) lib/active_support/tagged_logging.rb:99:in `block in tagged'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[activesupport (7.0.4.1) lib/active_support/tagged_logging.rb:37:in `tagged'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[activesupport (7.0.4.1) lib/active_support/tagged_logging.rb:99:in `tagged'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[railties (7.0.4.1) lib/rails/rack/logger.rb:25:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/middleware/remote_ip.rb:93:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[request_store (1.5.1) lib/request_store/middleware.rb:19:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/middleware/request_id.rb:26:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[rack (2.2.6.2) lib/rack/method_override.rb:24:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[rack (2.2.6.2) lib/rack/runtime.rb:22:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[activesupport (7.0.4.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/middleware/server_timing.rb:61:in `block in call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/middleware/server_timing.rb:26:in `collect_events'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/middleware/server_timing.rb:60:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/middleware/executor.rb:14:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/middleware/static.rb:23:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[rack (2.2.6.2) lib/rack/sendfile.rb:110:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[actionpack (7.0.4.1) lib/action_dispatch/middleware/host_authorization.rb:137:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[railties (7.0.4.1) lib/rails/engine.rb:530:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[puma (5.6.5) lib/puma/configuration.rb:252:in `call'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[puma (5.6.5) lib/puma/request.rb:77:in `block in handle_request'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[puma (5.6.5) lib/puma/thread_pool.rb:340:in `with_force_shutdown'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[puma (5.6.5) lib/puma/request.rb:76:in `handle_request'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[puma (5.6.5) lib/puma/server.rb:443:in `process_client'](http://localhost:3000/admin/game?model_name=game&sort=icon#)
[puma (5.6.5) lib/puma/thread_pool.rb:147:in `block in spawn_thread'](http://localhost:3000/admin/game?model_name=game&sort=icon#)