-
-
Notifications
You must be signed in to change notification settings - Fork 810
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
Comments
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. |
This actually only occurs on Rails 4.2+, all green with Rails 4.0/4.1. |
@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. |
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' |
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 ❤️ |
Or even just a failing spec 😃 |
…bject's klass. Addresses activerecord-hackery#518
I note you said your fix was hacky... wait til you see mine! This fixes the issue for me. I'm unable to run the tests since I don't have mysql installed. |
Thanks! 👍 I'm only able to reproduce this issue with a failing spec doing Until now, the Ransack form helper specs have all been testing variants of So help me out (maybe I'm missing something obvious): Why are you using |
Your fix does allow the following new failing spec (using # 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:
|
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! |
OK, great. Closing this for now. |
I am seeing the same issue with Workaround:
require 'ransack'
module Ransack::Naming
def model_name
self.class.model_name
end
end |
@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! |
Tests are passing now and I'm no longer able to reproduce the issue.
@glebm ping ;) |
@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. |
OK :( No problem. I'll credit you in the change log. |
* 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 ...
@jonatack your approach changes form namespace, for example for class 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 |
I had a similar problem ( 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 Hope this helps anyone who winds up here through an Internet search. |
Hello,
I'm running Rails
4.2
andI have the following error:
in here
Here is the action:
Backtrace:
The text was updated successfully, but these errors were encountered: