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 `model_name' for Ransack::Search #518

Closed
zenati opened this issue Mar 5, 2015 · 18 comments
Closed

undefined method `model_name' for Ransack::Search #518

zenati opened this issue Mar 5, 2015 · 18 comments
Assignees

Comments

@zenati
Copy link

zenati commented Mar 5, 2015

Hello,
I'm running Rails 4.2 and

gem 'ransack', github: 'activerecord-hackery/ransack'

I have the following error:

undefined method `model_name' for Ransack::Search

in here

= simple_form_for @q, method: :get do |form| # This line
  = form.input :region_id_eq, collection: Region.ordered

Here is the action:

  def index
    @q = Wine.search(params[:q])
    @wines = @q.result.page(params[:page])
  end

Backtrace:

NoMethodError - undefined method `model_name' for Ransack::Search<class: Wine, base: Grouping <combinator: and>>:Ransack::Search:
   () Users/zenati/.rvm/gems/ruby-2.1.5@lacavedivry/bundler/gems/ransack-3e4b6e34abc4/lib/ransack/search.rb:113:in `method_missing'
  actionpack (4.2.0) lib/action_controller/model_naming.rb:9:in `model_name_from_record_or_class'
  actionview (4.2.0) lib/action_view/record_identifier.rb:47:in `dom_class'
   () Users/zenati/.rvm/gems/ruby-2.1.5@lacavedivry/bundler/gems/simple_form-749c926140ee/lib/simple_form/action_view_extensions/form_helper.rb:62:in `simple_form_css_class'
   () Users/zenati/.rvm/gems/ruby-2.1.5@lacavedivry/bundler/gems/simple_form-749c926140ee/lib/simple_form/action_view_extensions/form_helper.rb:22:in `simple_form_for'
  app/views/wines/index.html.haml:6:in `_app_views_wines_index_html_haml___3716808230176255752_70261179357660'
  actionview (4.2.0) lib/action_view/template.rb:145:in `block in render'
  activesupport (4.2.0) lib/active_support/notifications.rb:166:in `instrument'
  actionview (4.2.0) lib/action_view/template.rb:333:in `instrument'
  actionview (4.2.0) lib/action_view/template.rb:143:in `render'
  actionview (4.2.0) lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
  actionview (4.2.0) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
  activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
  actionview (4.2.0) lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
  actionview (4.2.0) lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
  actionview (4.2.0) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
  actionview (4.2.0) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
  actionview (4.2.0) lib/action_view/renderer/template_renderer.rb:14:in `render'
  actionview (4.2.0) lib/action_view/renderer/renderer.rb:42:in `render_template'
  actionview (4.2.0) lib/action_view/renderer/renderer.rb:23:in `render'
  actionview (4.2.0) lib/action_view/rendering.rb:100:in `_render_template'
  actionpack (4.2.0) lib/action_controller/metal/streaming.rb:217:in `_render_template'
  actionview (4.2.0) lib/action_view/rendering.rb:83:in `render_to_body'
  actionpack (4.2.0) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
  actionpack (4.2.0) lib/action_controller/metal/renderers.rb:37:in `render_to_body'
  actionpack (4.2.0) lib/abstract_controller/rendering.rb:25:in `render'
  actionpack (4.2.0) lib/action_controller/metal/rendering.rb:16:in `render'
  actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
  activesupport (4.2.0) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
  /Users/zenati/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
  activesupport (4.2.0) lib/active_support/core_ext/benchmark.rb:12:in `ms'
  actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
  actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
  activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
  actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:40:in `render'
  actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
  actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
  actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'
  actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
  activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
  activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
  activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
  activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
  activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
  activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
  activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
  activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
  activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
  activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
  activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
  actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.2.0) lib/abstract_controller/base.rb:137:in `process'
  actionview (4.2.0) lib/action_view/rendering.rb:30:in `process'
  actionpack (4.2.0) lib/action_controller/metal.rb:195:in `dispatch'
  actionpack (4.2.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.2.0) lib/action_controller/metal.rb:236:in `block in action'
  actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
  actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in `serve'
  actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
  actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
  actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
  warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.3) lib/warden/manager.rb:34:in `call'
  rack (1.6.0) lib/rack/etag.rb:24:in `call'
  rack (1.6.0) lib/rack/conditionalget.rb:25:in `call'
  rack (1.6.0) lib/rack/head.rb:13:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
  rack (1.6.0) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.6.0) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
  activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
  activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
  activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  web-console (2.1.0) lib/web_console/middleware.rb:37:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
   () Users/zenati/.rvm/gems/ruby-2.1.5@lacavedivry/bundler/gems/quiet_assets-a6fb6e883375/lib/quiet_assets.rb:30:in `call_with_quiet_assets'
  request_store (1.1.0) lib/request_store/middleware.rb:8:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.0) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.0) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  rack (1.6.0) lib/rack/lock.rb:17:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
  rack (1.6.0) lib/rack/sendfile.rb:113:in `call'
  railties (4.2.0) lib/rails/engine.rb:518:in `call'
  railties (4.2.0) lib/rails/application.rb:164:in `call'
  rack (1.6.0) lib/rack/content_length.rb:15:in `call'
  unicorn (4.8.3) lib/unicorn/http_server.rb:576:in `process_client'
  unicorn (4.8.3) lib/unicorn/http_server.rb:670:in `worker_loop'
  unicorn (4.8.3) lib/unicorn/http_server.rb:525:in `spawn_missing_workers'
  unicorn (4.8.3) lib/unicorn/http_server.rb:140:in `start'
  unicorn-rails (2.2.0) lib/unicorn_rails.rb:33:in `run'
  rack (1.6.0) lib/rack/server.rb:286:in `start'
  railties (4.2.0) lib/rails/commands/server.rb:80:in `start'
  railties (4.2.0) lib/rails/commands/commands_tasks.rb:80:in `block in server'
  railties (4.2.0) lib/rails/commands/commands_tasks.rb:75:in `server'
  railties (4.2.0) lib/rails/commands/commands_tasks.rb:39:in `run_command!'
  railties (4.2.0) lib/rails/commands.rb:17:in `<top (required)>'
  bin/rails:8:in `<top (required)>'
  spring (1.3.3) lib/spring/client/rails.rb:27:in `call'
  spring (1.3.3) lib/spring/client/command.rb:7:in `call'
  spring (1.3.3) lib/spring/client.rb:26:in `run'
  spring (1.3.3) bin/spring:48:in `<top (required)>'
  spring (1.3.3) lib/spring/binstub.rb:11:in `<top (required)>'
  bin/spring:13:in `<top (required)>'
  bin/rails:3:in `<main>'
@fdwillis
Copy link

fdwillis commented Mar 5, 2015

Getting this same error!

I actually just restarted my heroku app dynos and it worked for me. Be sure you have the attribute 'region_id' in the database for said model.

@zenati
Copy link
Author

zenati commented Mar 16, 2015

This actually only occurs on Rails 4.2+, all green with Rails 4.0/4.1.

@jonatack
Copy link
Contributor

@zenati I can confirm that I'm having the same issue with Ransack master running Rails 4.2.1 and 5.0.0 / Ruby 2.2.1.

@jtippett
Copy link

I'm still having what appears to be this exact issue, running off master. Is it working now for anyone else?

The offending code:

<%= form_for User.search, url: [:admin, :users], method: :get do |f| %>

backtrace (note gem version):

NoMethodError - undefined method `model_name' for Ransack::Search<class: User, base: Grouping <combinator: and>>:Ransack::Search:
   () Users/james/.rvm/gems/ruby-2.2.0@myapp/bundler/gems/ransack-65c59b09667b/lib/ransack/search.rb:113:in `method_missing'
  actionpack (4.2.1) lib/action_controller/model_naming.rb:9:in `model_name_from_record_or_class'
  actionview (4.2.1) lib/action_view/helpers/form_helper.rb:433:in `form_for'
  haml (4.0.6) lib/haml/helpers/action_view_mods.rb:139:in `form_for_with_haml'
  haml (4.0.6) lib/haml/helpers/action_view_xss_mods.rb:28:in `form_for_with_haml_xss'
  app/views/layouts/admin/_navigation.html.erb:2:in `_app_views_layouts_admin__navigation_html_erb__3660276614508867726_70356578661480'
  actionview (4.2.1) lib/action_view/template.rb:145:in `block in render'
  activesupport (4.2.1) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.1) lib/active_support/notifications.rb:164:in `instrument'
  actionview (4.2.1) lib/action_view/template.rb:333:in `instrument'
  actionview (4.2.1) lib/action_view/template.rb:143:in `render'
  xray-rails (0.1.15) lib/xray/engine.rb:33:in `render_with_xray'
  actionview (4.2.1) lib/action_view/renderer/partial_renderer.rb:339:in `render_partial'
  actionview (4.2.1) lib/action_view/renderer/partial_renderer.rb:310:in `block in render'
  actionview (4.2.1) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
  activesupport (4.2.1) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.1) lib/active_support/notifications.rb:164:in `instrument'
  actionview (4.2.1) lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
  actionview (4.2.1) lib/action_view/renderer/partial_renderer.rb:309:in `render'
  actionview (4.2.1) lib/action_view/renderer/renderer.rb:47:in `render_partial'
  actionview (4.2.1) lib/action_view/helpers/rendering_helper.rb:35:in `render'
  haml (4.0.6) lib/haml/helpers/action_view_mods.rb:10:in `block in render_with_haml'
  haml (4.0.6) lib/haml/helpers.rb:89:in `non_haml'
  haml (4.0.6) lib/haml/helpers/action_view_mods.rb:10:in `render_with_haml'
  app/views/layouts/admin.html.haml:17:in `_app_views_layouts_admin_html_haml__4539354067511048006_70356577340880'
  actionview (4.2.1) lib/action_view/template.rb:145:in `block in render'
  activesupport (4.2.1) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.1) lib/active_support/notifications.rb:164:in `instrument'
  actionview (4.2.1) lib/action_view/template.rb:333:in `instrument'
  actionview (4.2.1) lib/action_view/template.rb:143:in `render'
  xray-rails (0.1.15) lib/xray/engine.rb:33:in `render_with_xray'
  actionview (4.2.1) lib/action_view/renderer/template_renderer.rb:66:in `render_with_layout'
  actionview (4.2.1) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
  actionview (4.2.1) lib/action_view/renderer/template_renderer.rb:14:in `render'
  actionview (4.2.1) lib/action_view/renderer/renderer.rb:42:in `render_template'
  actionview (4.2.1) lib/action_view/renderer/renderer.rb:23:in `render'
  actionview (4.2.1) lib/action_view/rendering.rb:100:in `_render_template'
  actionpack (4.2.1) lib/action_controller/metal/streaming.rb:217:in `_render_template'
  actionview (4.2.1) lib/action_view/rendering.rb:83:in `render_to_body'
  actionpack (4.2.1) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
  actionpack (4.2.1) lib/action_controller/metal/renderers.rb:37:in `render_to_body'
  actionpack (4.2.1) lib/abstract_controller/rendering.rb:25:in `render'
  actionpack (4.2.1) lib/action_controller/metal/rendering.rb:16:in `render'
  actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
  activesupport (4.2.1) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
  /Users/james/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
  activesupport (4.2.1) lib/active_support/core_ext/benchmark.rb:12:in `ms'
  actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
  actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
  activerecord (4.2.1) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
  actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:43:in `render'
  actionpack (4.2.1) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
  actionpack (4.2.1) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
  actionpack (4.2.1) lib/abstract_controller/base.rb:198:in `process_action'
  actionpack (4.2.1) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.2.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (4.2.1) lib/active_support/callbacks.rb:117:in `call'
  activesupport (4.2.1) lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
  activesupport (4.2.1) lib/active_support/callbacks.rb:505:in `call'
  activesupport (4.2.1) lib/active_support/callbacks.rb:92:in `_run_callbacks'
  activesupport (4.2.1) lib/active_support/callbacks.rb:776:in `_run_process_action_callbacks'
  activesupport (4.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.1) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (4.2.1) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
  activesupport (4.2.1) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.1) lib/active_support/notifications.rb:164:in `instrument'
  actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.2.1) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.2.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.2.1) lib/abstract_controller/base.rb:137:in `process'
  actionview (4.2.1) lib/action_view/rendering.rb:30:in `process'
  actionpack (4.2.1) lib/action_controller/metal.rb:196:in `dispatch'
  actionpack (4.2.1) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.2.1) lib/action_controller/metal.rb:237:in `block in action'
  actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
  actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:43:in `serve'
  actionpack (4.2.1) lib/action_dispatch/journey/router.rb:43:in `block in serve'
  actionpack (4.2.1) lib/action_dispatch/journey/router.rb:30:in `serve'
  actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:819:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  xray-rails (0.1.15) lib/xray/middleware.rb:37:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  bullet (4.14.4) lib/bullet/rack.rb:12:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  meta_request (0.3.4) lib/meta_request/middlewares/app_request_handler.rb:13:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  meta_request (0.3.4) lib/meta_request/middlewares/meta_request_handler.rb:13:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/rack/agent_hooks.rb:30:in `traced_call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/rack/browser_monitoring.rb:23:in `traced_call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/rack/developer_mode.rb:56:in `traced_call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.3) lib/warden/manager.rb:34:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  rack (1.6.0) lib/rack/etag.rb:24:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  rack (1.6.0) lib/rack/conditionalget.rb:25:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  rack (1.6.0) lib/rack/head.rb:13:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/flash.rb:260:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  rack (1.6.0) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.6.0) lib/rack/session/abstract/id.rb:220:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  activerecord (4.2.1) lib/active_record/query_cache.rb:36:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  activerecord (4.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:649:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.1) lib/active_support/callbacks.rb:88:in `_run_callbacks'
  activesupport (4.2.1) lib/active_support/callbacks.rb:776:in `_run_call_callbacks'
  activesupport (4.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  bugsnag (2.8.1) lib/bugsnag/rack.rb:31:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  rack-contrib (1.2.0) lib/rack/contrib/response_headers.rb:17:in `call'
  meta_request (0.3.4) lib/meta_request/middlewares/headers.rb:16:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  railties (4.2.1) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.1) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.1) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.1) lib/rails/rack/logger.rb:20:in `call'
  quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  rack (1.6.0) lib/rack/methodoverride.rb:22:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  rack (1.6.0) lib/rack/runtime.rb:18:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  activesupport (4.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  rack-rewrite (1.5.1) lib/rack/rewrite.rb:24:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  rack (1.6.0) lib/rack/lock.rb:17:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/static.rb:113:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  rack (1.6.0) lib/rack/sendfile.rb:113:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  lib/middleware/turbo_dev.rb:33:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  railties (4.2.1) lib/rails/engine.rb:518:in `call'
  railties (4.2.1) lib/rails/application.rb:164:in `call'
  newrelic_rpm (3.11.0.283) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
  rack (1.6.0) lib/rack/urlmap.rb:66:in `block in call'
  rack (1.6.0) lib/rack/urlmap.rb:50:in `call'

@jonatack
Copy link
Contributor

It's very possible. As written in the commit, the issue needs to be fixed in a better way. Pull requests to fix it are most welcome ❤️

@jonatack jonatack reopened this Mar 23, 2015
@jonatack
Copy link
Contributor

Or even just a failing spec 😃

jtippett added a commit to jtippett/ransack that referenced this issue Mar 23, 2015
@jtippett
Copy link

I note you said your fix was hacky... wait til you see mine!

jtippett@71469d3

This fixes the issue for me. I'm unable to run the tests since I don't have mysql installed.

@jonatack
Copy link
Contributor

Thanks! 👍

I'm only able to reproduce this issue with a failing spec doing form_for instead of search_form_for.

Until now, the Ransack form helper specs have all been testing variants of search_form_for (and sort_link), the two view helpers added by Ransack.

So help me out (maybe I'm missing something obvious): Why are you using form_for with a Ransack search object?

@jonatack
Copy link
Contributor

Your fix does allow the following new failing spec (using form_for) to pass:

# spec/ransack/helpers/form_helper_spec.rb

describe '#form_for with an array of routes' do
  subject {
    @controller.view_context
    .form_for([:admin, Comment.search]) {}
  }
  it { should match /action="\/admin\/comments"/ }
end

Without your fix, the test fails with the following trace:

Failures:

  1) Ransack::Helpers::FormHelper#form_for with an array of routes
     Failure/Error: .form_for([:admin, Comment.search]) {}
     NoMethodError:
       undefined method `model_name' for Ransack::Search<class: Comment, base: Grouping <combinator: and>>:Ransack::Search
     # ./lib/ransack/search.rb:113:in `method_missing'
     # /Users/jonatack/.rvm/gems/ruby-2.2.1/bundler/gems/rails-9a7122c72cb5/actionpack/lib/action_controller/model_naming.rb:9:in `model_name_from_record_or_class'
     # /Users/jonatack/.rvm/gems/ruby-2.2.1/bundler/gems/rails-9a7122c72cb5/actionview/lib/action_view/helpers/form_helper.rb:433:in `form_for'
     # ./spec/ransack/helpers/form_helper_spec.rb:389:in `block (3 levels) in <module:Helpers>'

@jtippett
Copy link

Why are you using form_for with a Ransack search object?

Honestly, this is a legacy admin console, and that's what the previous devs did - I didn't even know about search_form_for. I'm going to change to use that now.

My "fix" it turns out not to work anyway (the form works but the search is broken) and it's for the wrong problem - trying to fool actionpack into thinking a search form is actually for an AR object. Probably a bad idea.

Thanks a lot for shedding light on the issues and telling me about search_form_for!

@jonatack
Copy link
Contributor

OK, great. Closing this for now.

@glebm
Copy link
Contributor

glebm commented Mar 28, 2015

I am seeing the same issue with simple_form_for and Rails 4.2.1, but not Rails 4.0.13.

Workaround:

config/initializers/ransack.rb:

require 'ransack'

module Ransack::Naming
  def model_name
    self.class.model_name
  end
end

@jonatack jonatack reopened this Mar 29, 2015
@jonatack jonatack self-assigned this Mar 29, 2015
@jonatack
Copy link
Contributor

@glebm would you like to make a PR to Ransack master to add your workaround to Ransack::Naming at line 24? It looks like it would solve this for everyone.

  def model_name
    self.class.model_name
  end

Thanks!

jonatack referenced this issue Mar 30, 2015
Tests are passing now and I'm no longer able to reproduce the issue.
@jonatack
Copy link
Contributor

@glebm ping ;)

@glebm
Copy link
Contributor

glebm commented Mar 31, 2015

@jonatack Sure, I'd love to submit a PR, but I actually need to get a permission from my employer first. :( Feel free to patch it yourself please.

@jonatack
Copy link
Contributor

OK :( No problem. I'll credit you in the change log.

avit added a commit to avit/ransack that referenced this issue Jul 8, 2015
* association-conditions-rails3: (365 commits)
  Avoid overwriting association conditions with default scope
  Only patch default conditions once
  Compare and adjust German locale with localeapp translation
  [skip ci] German locale file (de.yml)
  Fix RSpec `its` method deprecation warning
  Clearer method and method call not in iteration
  Replace deprecated RSpec syntax
  Use fewer conditionals & simplify the required files
  [skip ci] Update changelog/readme and bump to version 1.6.6
  Use latest Polyamorous release
  [skip ci] README: Fix RubyGems YARD rendering, add Code Climate
  [skip ci] Update changelog for 631d104, 12c6b8f
  Fix activerecord-hackery#518: undefined method `model_name`
  Add Ruby version to specs info header
  Updated AR-specific reference to use Polyamorous
  Revert 746f35e, remove patch for Rails 4.2.1/5.0.0
  [skip ci] Update year to 2015
  Fix erroneous reference to AR class
  Bump to version 1.6.5 (Rails 5 release)
  [skip ci] More docs updates
  ...
@amenzhinsky
Copy link

@jonatack your approach changes form namespace, for example for class Employee it will be employee[name_eq] instead of q[name_eq] that breaks controller's logic Employee.search(params[:q])

I would add this for compatibility with old code base

module SimpleForm::ActionViewExtensions::FormHelper
  alias_method :original_simple_form_for, :simple_form_for

  def simple_form_for(record, options = {}, &block)
    if record.instance_of?(Ransack::Search) && !options.key?(:as)
      options[:as] = :q
    end

    original_simple_form_for(record, options, &block)
  end
end

@nossidge
Copy link

I had a similar problem (undefined method 'name' for Ransack::Search) but managed to fix it:

This failed:

= simple_form_for(@q, method: :get) do |f|
  = f.input :something_cont

This worked:

= simple_form_for(@q, method: :get, url: something_path) do |f|
  = f.input :something_cont

You need a url: parameter, even if GETting the same URL you are on (so you can't rely on the fact that that's the default).

Hope this helps anyone who winds up here through an Internet search.

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

7 participants