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

Filters broken with mongoid field alias #1766

Closed
sepastian opened this issue Sep 27, 2013 · 2 comments
Closed

Filters broken with mongoid field alias #1766

sepastian opened this issue Sep 27, 2013 · 2 comments

Comments

@sepastian
Copy link

I am using rails_admin with mongoid. When using mongoid's :as options, filters in rails_admin stop working.

For example, the following works as expected:

class A
    include Mongoid::Document
    field :long_name, :type => String
    rails_admin do
        list do
            filters [ :long_name ]
            field :long_name
        end
    end
end

While this does not:

class A
    include Mongoid::Document
    field :long_name, :as => :l, :type => String
    rails_admin do
        list do
            filters [ :long_name ]
            field :long_name
        end
    end
end

The name of the field has changed from :long_name to :l, :long_name is now stored in field.options[:as]. Mongoid maps between both names transparently, rails_admin does not. A workaround exists:

class A
    include Mongoid::Document
    field :long_name, :as => :l, :type => String
    rails_admin do
        list do
            filters [ :l ]
            field :l
        end
    end
end

For better readability and consistency with mongoid's behavior, rails_admin should map between field names and aliases. It should be possible to use either the field name or the alias everywhere.

I would like to provide a pull request, if you can point me in the right direction. Is there a central place in rails_admin's mongoid adapter where field name resolution is taking place? Where should I start looking, or how would you go about improving this?

@sepastian
Copy link
Author

And here's a stack trace:

/home/sebastian/Code/rails_admin/app/views/rails_admin/main/index.html.haml:39:in block in __home_sebastian__ode_rails_admin_app_views_rails_admin_main_index_html_haml___1068259551_93640420' /home/sebastian/Code/rails_admin/app/views/rails_admin/main/index.html.haml:33:inmap'
/home/sebastian/Code/rails_admin/app/views/rails_admin/main/index.html.haml:33:in __home_sebastian__ode_rails_admin_app_views_rails_admin_main_index_html_haml___1068259551_93640420' actionpack (4.0.0) lib/action_view/template.rb:143:inblock in render'
activesupport (4.0.0) lib/active_support/notifications.rb:161:in instrument' actionpack (4.0.0) lib/action_view/template.rb:141:inrender'
actionpack (4.0.0) lib/action_view/renderer/template_renderer.rb:49:in block (2 levels) in render_template' actionpack (4.0.0) lib/action_view/renderer/abstract_renderer.rb:38:inblock in instrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in block in instrument' activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:ininstrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in instrument' actionpack (4.0.0) lib/action_view/renderer/abstract_renderer.rb:38:ininstrument'
actionpack (4.0.0) lib/action_view/renderer/template_renderer.rb:48:in block in render_template' actionpack (4.0.0) lib/action_view/renderer/template_renderer.rb:56:inrender_with_layout'
actionpack (4.0.0) lib/action_view/renderer/template_renderer.rb:47:in render_template' actionpack (4.0.0) lib/action_view/renderer/template_renderer.rb:17:inrender'
actionpack (4.0.0) lib/action_view/renderer/renderer.rb:42:in render_template' actionpack (4.0.0) lib/action_view/renderer/renderer.rb:23:inrender'
actionpack (4.0.0) lib/abstract_controller/rendering.rb:127:in _render_template' actionpack (4.0.0) lib/action_controller/metal/streaming.rb:219:in_render_template'
actionpack (4.0.0) lib/abstract_controller/rendering.rb:120:in render_to_body' actionpack (4.0.0) lib/action_controller/metal/rendering.rb:33:inrender_to_body'
actionpack (4.0.0) lib/action_controller/metal/renderers.rb:26:in render_to_body' actionpack (4.0.0) lib/abstract_controller/rendering.rb:97:inrender'
actionpack (4.0.0) lib/action_controller/metal/rendering.rb:16:in render' actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:41:inblock (2 levels) in render'
activesupport (4.0.0) lib/active_support/core_ext/benchmark.rb:12:in block in ms' /usr/lib/ruby/1.9.1/benchmark.rb:295:inrealtime'
activesupport (4.0.0) lib/active_support/core_ext/benchmark.rb:12:in ms' actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:41:inblock in render'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:84:in cleanup_view_runtime' actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:40:inrender'
remotipart (1.2.1) lib/remotipart/render_overrides.rb:14:in render_with_remotipart' /home/sebastian/Code/rails_admin/lib/rails_admin/config/actions/index.rb:35:inblock (4 levels) in class:Index'
actionpack (4.0.0) lib/action_controller/metal/mime_responds.rb:191:in call' actionpack (4.0.0) lib/action_controller/metal/mime_responds.rb:191:inrespond_to'
/home/sebastian/Code/rails_admin/lib/rails_admin/config/actions/index.rb:32:in block (2 levels) in <class:Index>' (eval):8:ininstance_eval'
(eval):8:in index' actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:insend_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:189:in process_action' actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:inprocess_action'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:in block in process_action' activesupport (4.0.0) lib/active_support/callbacks.rb:463:in_run__319947751__process_action__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in run_callbacks' actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:inprocess_action'
actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in process_action' actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:inblock in process_action'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in block in instrument' activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:ininstrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in instrument' actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:inprocess_action'
actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in process_action' actionpack (4.0.0) lib/abstract_controller/base.rb:136:inprocess'
actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in process' actionpack (4.0.0) lib/action_controller/metal.rb:195:indispatch'
actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in dispatch' actionpack (4.0.0) lib/action_controller/metal.rb:231:inblock in action'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in call' actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:indispatch'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in call' actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:inblock in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in each' actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:incall'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in call' railties (4.0.0) lib/rails/engine.rb:511:incall'
railties (4.0.0) lib/rails/railtie/configurable.rb:30:in method_missing' actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:inblock in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in each' actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:incall'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in call' rack-pjax (0.7.0) lib/rack/pjax.rb:12:incall'
/home/sebastian/.bundler/ruby/1.9.1/mongoid-b84b811d4777/lib/rack/mongoid/middleware/identity_map.rb:34:in block in call' /home/sebastian/.bundler/ruby/1.9.1/mongoid-b84b811d4777/lib/mongoid/unit_of_work.rb:39:inunit_of_work'
/home/sebastian/.bundler/ruby/1.9.1/mongoid-b84b811d4777/lib/rack/mongoid/middleware/identity_map.rb:34:in call' warden (1.2.3) lib/warden/manager.rb:35:inblock in call'
warden (1.2.3) lib/warden/manager.rb:34:in catch' warden (1.2.3) lib/warden/manager.rb:34:incall'
rack (1.5.2) lib/rack/etag.rb:23:in call' rack (1.5.2) lib/rack/conditionalget.rb:25:incall'
rack (1.5.2) lib/rack/head.rb:11:in call' remotipart (1.2.1) lib/remotipart/middleware.rb:27:incall'
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in call' actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:incall'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in context' rack (1.5.2) lib/rack/session/abstract/id.rb:220:incall'
actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in call' actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:inblock in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in _run__28556109__call__callbacks' activesupport (4.0.0) lib/active_support/callbacks.rb:80:inrun_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in call' actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:incall'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in call' actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:incall'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in call' railties (4.0.0) lib/rails/rack/logger.rb:38:incall_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in block in call' activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:inblock in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in tagged' activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:intagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in call' actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:incall'
rack (1.5.2) lib/rack/methodoverride.rb:21:in call' rack (1.5.2) lib/rack/runtime.rb:17:incall'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in call' rack (1.5.2) lib/rack/lock.rb:17:incall'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in call' railties (4.0.0) lib/rails/engine.rb:511:incall'
railties (4.0.0) lib/rails/application.rb:97:in call' rack (1.5.2) lib/rack/lock.rb:17:incall'
rack (1.5.2) lib/rack/content_length.rb:14:in call' rack (1.5.2) lib/rack/handler/webrick.rb:60:inservice'
/usr/lib/ruby/1.9.1/webrick/httpserver.rb:138:in service' /usr/lib/ruby/1.9.1/webrick/httpserver.rb:94:inrun'
/usr/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

@mshibuya
Copy link
Member

Dup of #1745.

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

2 participants