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 `users_user_id_eq' for Ransack::Search<class: Detail, base: Grouping <combinator: and>>:Ransack::Search #2565

Closed
perkins2099 opened this issue Oct 13, 2013 · 68 comments
Milestone

Comments

@perkins2099
Copy link

Error: undefined method `users_user_id_eq' for Ransack::Search<class: Detail, base: Grouping <combinator: and>>:Ransack::Search

Rails 4, Ruby 2. Latest version of Active Admin.

Added basic admin functionality to a model I have called Detail. Not sure what is going on or what info might be needed to troubleshoot the bug.

Thanks for any help.

@seanlinsley
Copy link
Contributor

Can you run this and report on the results?

ActiveAdmin.application.namespaces[:admin].resources[:Detail].filters

@perkins2099
Copy link
Author

Sure you bet:

=> {:competitor_details=>{}, :competitors=>{}, :collections=>{}, :users=>{}, :authentications=>{}, :reports=>{}, :created_at=>{}, :updated_at=>{}, :params=>{}}

@seanlinsley
Copy link
Contributor

Hmm... and I assume you don't have any custom filters set up, and a Detail belongs_to a User?

@seanlinsley
Copy link
Contributor

The structure of that method (users_user_id_eq) reminds me of the has_many :through functionality added in #2541

@perkins2099
Copy link
Author

I did at one point(In another admin .rb file) but took them out as I didn't need them any more.
Perhaps the relation is too complicated? Detail has many users..through competitors. Competitors has_many details through competitor details.. Competitor belongs_to a user.

ActiveAdmin.register Detail do
  menu :parent => "Models"

  index do
    column :id
    column :type
    column :created_at
    column :params
    actions
  end

end

class Detail < ActiveRecord::Base

  has_many :competitor_details, dependent: :destroy
  has_many :competitors, through: :competitor_details
  has_many :users, through: :competitors
  # ...
end

@seanlinsley
Copy link
Contributor

Ah, yeah we aren't correctly handling nested has_many :through relationships. For now, you can just remove that filter:

ActiveAdmin.register Detail do
  remove_filter :users
end

@seanlinsley
Copy link
Contributor

@shekibobo any idea on how to detect nested HMT associations?

@perkins2099
Copy link
Author

@daxter - Awesome. Thanks so much for the help; wasn't finding it from searching. That fixed the problem.

@seanlinsley
Copy link
Contributor

Well, it hid the problem :V

@perkins2099
Copy link
Author

True.. :) Should I close or leave open for HMT?

@seanlinsley
Copy link
Contributor

Yeah definitely leave this open. We'll get this fixed.

@shekibobo
Copy link
Contributor

Yeah this is gonna be a fun one. Might even get recursive.

Rough brainstorm on this:

reflection_chain = []
r = reflection
while r.through_reflection
  reflection_chain << r.through_reflection.name
  r = r.through_reflection
end
reflection_chain.reverse! << reflection.source_reflection.foreign_key
name = reflection_chain.join('_')

Search appears to work on the command line. Running through wwtd right now. I'll submit a pull request if it passes.

@shekibobo
Copy link
Contributor

@perkins2099 Can you set the filter to filter :users, as: :check_boxes and tell me the error message, if any?

@shekibobo
Copy link
Contributor

So, I've found a way to build this association chain, but I don't think Ransack supports nesting associations that deeply.

I have an association chain like so:

A has many B.
B has many C.
A has many C through B.

C has many D.
D has many E.
C has many E through D.

A has many E through C.

This is probably a terrible way to use through associations, but even so, I want to filter A by E. For a single through association, we would use the search method named:

Bs_C_id_eq

That is, the through association name, and the target association foreign key.

So in the case of filtering A by E, we would presumably follow this pattern:

Bs_Cs_Ds_E_id_eq

My first implementation would not support this, because the through associations don't exist between every association. We need to track the association chain all the way through.

TIL Reflection#chain ❤️

def input_name
  return method if seems_searchable?

  # Deal with has_many :through relationships in filters
  # If the relationship is a HMT, we set the search logic to be something
  # like :#{through_association}_#{end_association_id}.
  if through_association?
    chain = reflection.chain.slice(1..-1).reverse.map(&:name) << reflection.foreign_key
    name = chain.join('_')
  else
    name = method.to_s
    name.concat '_id' if reflection
  end
  name.concat multiple? ? '_in' : '_eq'
end

reflection.chain #=> [:Es, :Ds, :Cs, :Bs]
# we need to get rid of :Es and replace it with :E_id, then reverse it and join by '_'

The above code gives us the method chain I would think would work, but I still get an error message about the search method in my app.

Wondering if we can get some input from the good people on the Ransack team?

@seanlinsley
Copy link
Contributor

What's the error you get?

If it's too complicated, maybe we should just prevent nested HMT associations from being added to the default list of filters.

@shekibobo
Copy link
Contributor

Might be the best bet. I get an error that the method I created, i.e. :bs_cs_ds_e_id_eq was not found. I believe it was a ransack error, but I'd have to double check, and I'm not at my computer right now. I did ping @radar on Twitter about the depth of association searches in Ransack, and am waiting to hear back from him. Might just be my assumption about how those search methods are formulated is wrong.

@shekibobo
Copy link
Contributor

undefined method `bs_cs_ds_e_id_eq' for Ransack::Search<class: A, base: Grouping <combinator: and>>:Ransack::Search

@perkins2099
Copy link
Author

@shekibobo - For the question regarding check boxes. I still get the error with those modifications

@shekibobo
Copy link
Contributor

@perkins2099 Could you try my branch and see if it fixes your issue?

gem 'activeadmin', github: 'shekibobo/active_admin', branch: '2565-fix-nested-through-filters'

@shekibobo
Copy link
Contributor

It looks like my assumption of being able to just chain association names together was flat out wrong, but now it's clear to me why. They work on a single has_many :through because the foreign key we are search on is an actual attribute of the direct association. So, just like we can search by :association_name_eq, we can search by :association_other_foreign_key_eq. So simple.

I'm good with switching back to the old concatenation method if you want. The chain method works nicely, but it might seem a bit too much like magic to someone down the road.

@radar
Copy link

radar commented Oct 15, 2013

Seems like you all got it figured out before I came here. Glad :)

@shekibobo
Copy link
Contributor

Yup. Thanks for checking it out, though!

@perkins2099
Copy link
Author

@shekibobo - This branch works for me(Removed the remove_filter bits)! Thanks for the diligence.

@bughit
Copy link

bughit commented Oct 16, 2013

@shekibobo - I tried your branch, still have a problem

Showing ~/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/active_admin-ec00dc24600a/app/views/active_admin/resource/index.html.arb where line #1 raised:

undefined method `patient_plan_patient_plan_id_eq' for Ransack::Search<class: Patient, base: Grouping <combinator: and>>:Ransack::Search

seems to be caused by a has_many through: <has_one>

@shekibobo
Copy link
Contributor

@bughit Can you show me how the patient plan relationship is defined?

@shekibobo
Copy link
Contributor

@bughit Can you show me how you've defined the relationship for patient_plan? Can you also try using ref b9ab250?

gem 'activeadmin', github: 'shekibobo/active_admin', ref: 'b9ab2507dff0bea743a1595ee880d13280425492'

Let me know if that one works. Thanks.

@bughit
Copy link

bughit commented Oct 16, 2013

b9ab250 is not working.

class Patient < User

  has_one :patient_plan, inverse_of: :patient, dependent: :destroy

  has_many :patient_plan_goals, through: :patient_plan

@bughit
Copy link

bughit commented Oct 16, 2013

there's also another level of through nesting, has_many :patient_plan_goal_actions, through: :patient_plan_goals but it's the has_many in the previous post that's the current culprit

@shekibobo
Copy link
Contributor

I guess I hadn't considered a has_one :through case. I'll take a look at this tonight.

@kiddrew
Copy link

kiddrew commented May 2, 2014

I'm seeing the same issue as @jufemaiz. I have a HMT relationship where the join table has no ID column. In my case, the model list has_many domains through list_domains, and list_domains has a primary key on [list_id,domain_id]. I'm trying to assign those associations using a nested has_many :list_domains under the list form in active admin, and I'm getting this error:

undefined method 'list_domains_id_eq' for Ransack::Search<class: List, base: Grouping <combinator: and>>:Ransack::Search

@seanlinsley seanlinsley reopened this May 2, 2014
@kiddrew
Copy link

kiddrew commented May 3, 2014

I experimented a little this morning with the issue I'm seeing. I was expecting the offending line to be the has_many in the ActiveAdmin register class, but that's not the case - commenting it out did nothing. If I comment out the has_many :list_domains line in my List model, ActiveAdmin functions normally. As soon as I uncomment that line, I get the error above.

@Lordnibbler
Copy link

I am also seeing this issue still, and have had to invoke remove_filter for all of my HABTM relationships.

# app.rb
class App < ActiveRecord::Base
  has_and_belongs_to_many :users
  belongs_to :account
  has_many :versions, class_name: 'AppVersion', dependent: :destroy
  has_many :secondary_tokens, dependent: :destroy
  has_many :apps, through: :secondary_tokens

  # business logic
end
# user.rb
class User < ActiveRecord::Base
  belongs_to :account
  has_many :devices, dependent: :destroy

  # This allows a user to see any apps that is provided via roles
  has_many :apps_provided_by_roles, source: :apps, through: :account_roles

  has_and_belongs_to_many :apps
  has_and_belongs_to_many :account_roles

  # business logic
end
# backtrace
Showing /vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/app/views/active_admin/resource/index.html.arb where line #1 raised:

undefined method `apps_users_id_eq' for Ransack::Search<class: App, base: Grouping <combinator: and>>:Ransack::Search
Extracted source (around line #1):
1

  insert_tag renderer_for(:index)

Rails.root: REDACTED

Application Trace | Framework Trace | Full Trace
vendor/bundler/gems/ransack-1.2.3/lib/ransack/search.rb:86:in `method_missing'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/helpers/tags/base.rb:28:in `value'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/helpers/tags/select.rb:16:in `block in render'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/helpers/tags/select.rb:16:in `fetch'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/helpers/tags/select.rb:16:in `render'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/helpers/form_options_helper.rb:165:in `select'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/helpers/form_options_helper.rb:779:in `select'
vendor/bundler/gems/formtastic-2.3.0.rc3/lib/formtastic/inputs/select_input.rb:154:in `select_html'
vendor/bundler/gems/formtastic-2.3.0.rc3/lib/formtastic/inputs/select_input.rb:149:in `block in to_html'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer'
vendor/bundler/gems/haml-4.0.5/lib/haml/helpers/action_view_xss_mods.rb:5:in `with_output_buffer_with_haml_xss'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/helpers/capture_helper.rb:38:in `capture'
vendor/bundler/gems/haml-4.0.5/lib/haml/helpers/action_view_mods.rb:52:in `capture_with_haml'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/inputs/filter_base.rb:11:in `input_wrapping'
vendor/bundler/gems/formtastic-2.3.0.rc3/lib/formtastic/inputs/select_input.rb:146:in `to_html'
vendor/bundler/gems/formtastic-2.3.0.rc3/lib/formtastic/helpers/input_helper.rb:241:in `input'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/form_builder.rb:26:in `block in input'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/form_builder.rb:150:in `with_new_form_buffer'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/form_builder.rb:26:in `input'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/filters/forms.rb:16:in `filter'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/filters/forms.rb:71:in `block (2 levels) in active_admin_filters_form_for'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/filters/forms.rb:67:in `each'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/filters/forms.rb:67:in `block in active_admin_filters_form_for'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer'
vendor/bundler/gems/haml-4.0.5/lib/haml/helpers/action_view_xss_mods.rb:5:in `with_output_buffer_with_haml_xss'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/helpers/capture_helper.rb:38:in `capture'
vendor/bundler/gems/haml-4.0.5/lib/haml/helpers/action_view_mods.rb:52:in `capture_with_haml'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/helpers/form_helper.rb:434:in `form_for'
vendor/bundler/gems/haml-4.0.5/lib/haml/helpers/action_view_mods.rb:139:in `form_for_with_haml'
vendor/bundler/gems/haml-4.0.5/lib/haml/helpers/action_view_xss_mods.rb:28:in `form_for_with_haml_xss'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/filters/forms.rb:66:in `active_admin_filters_form_for'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element.rb:175:in `method_missing'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/filters/resource_extension.rb:128:in `block in filters_sidebar_section'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/views/components/sidebar_section.rb:20:in `instance_exec'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/views/components/sidebar_section.rb:20:in `build_sidebar_content'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/views/components/sidebar_section.rb:13:in `build'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:30:in `block in build_tag'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/context.rb:92:in `with_current_arbre_element'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:26:in `build_tag'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:39:in `insert_tag'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:14:in `sidebar_section'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/views/pages/base.rb:122:in `block (2 levels) in build_sidebar'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/views/pages/base.rb:121:in `collect'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/views/pages/base.rb:121:in `block in build_sidebar'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/context.rb:92:in `with_current_arbre_element'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:26:in `build_tag'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:39:in `insert_tag'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:14:in `div'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/views/pages/base.rb:120:in `build_sidebar'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/views/pages/base.rb:66:in `block in build_page_content'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/context.rb:92:in `with_current_arbre_element'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:26:in `build_tag'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:39:in `insert_tag'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:14:in `div'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/views/pages/base.rb:64:in `build_page_content'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/views/pages/base.rb:47:in `block (2 levels) in build_page'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/context.rb:92:in `with_current_arbre_element'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:26:in `build_tag'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:39:in `insert_tag'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:14:in `div'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/views/pages/base.rb:44:in `block in build_page'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/context.rb:92:in `with_current_arbre_element'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/views/pages/base.rb:43:in `build_page'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/lib/active_admin/views/pages/base.rb:10:in `build'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:30:in `block in build_tag'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/context.rb:92:in `with_current_arbre_element'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:26:in `build_tag'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/element/builder_methods.rb:39:in `insert_tag'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/app/views/active_admin/resource/index.html.arb:1:in `block in _vendor_bundler_bundler_gems_active_admin_cf_b_f__ab_e_app_views_active_admin_resource_index_html_arb__9397484507466979_70309021550460'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/context.rb:45:in `instance_eval'
vendor/bundler/gems/arbre-1.0.1/lib/arbre/context.rb:45:in `initialize'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/app/views/active_admin/resource/index.html.arb:1:in `new'
vendor/bundler/bundler/gems/active_admin-cf3b1f70ab0e/app/views/active_admin/resource/index.html.arb:1:in `_vendor_bundler_bundler_gems_active_admin_cf_b_f__ab_e_app_views_active_admin_resource_index_html_arb__9397484507466979_70309021550460'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/template.rb:145:in `block in render'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/notifications.rb:161:in `instrument'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/template.rb:339:in `instrument'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/template.rb:143:in `render'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/renderer/template_renderer.rb:55:in `block (2 levels) in render_template'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/notifications.rb:159:in `block in instrument'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/notifications.rb:159:in `instrument'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/renderer/template_renderer.rb:54:in `block in render_template'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/renderer/template_renderer.rb:62:in `render_with_layout'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/renderer/template_renderer.rb:53:in `render_template'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/renderer/template_renderer.rb:17:in `render'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/renderer/renderer.rb:42:in `render_template'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/renderer/renderer.rb:23:in `render'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/rendering.rb:99:in `_render_template'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/streaming.rb:217:in `_render_template'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/rendering.rb:82:in `render_to_body'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/rendering.rb:32:in `render_to_body'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/renderers.rb:32:in `render_to_body'
vendor/bundler/gems/actionpack-4.1.1/lib/abstract_controller/rendering.rb:25:in `render'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/rendering.rb:16:in `render'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
~/.rbenv/versions/2.1.1/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/core_ext/benchmark.rb:12:in `ms'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/instrumentation.rb:41:in `block in render'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
vendor/bundler/gems/activerecord-4.1.1/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/instrumentation.rb:40:in `render'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/implicit_render.rb:10:in `default_render'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/responder.rb:238:in `default_render'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/responder.rb:165:in `to_html'
vendor/bundler/gems/responders-1.0.0/lib/responders/flash_responder.rb:104:in `to_html'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/responder.rb:158:in `respond'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/responder.rb:151:in `call'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/mime_responds.rb:400:in `respond_with'
vendor/bundler/gems/inherited_resources-1.4.1/lib/inherited_resources/actions.rb:7:in `index'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
vendor/bundler/gems/actionpack-4.1.1/lib/abstract_controller/base.rb:189:in `process_action'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/rendering.rb:10:in `process_action'
vendor/bundler/gems/actionpack-4.1.1/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:113:in `call'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:113:in `call'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `block in halting'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `call'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `block in halting'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `call'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `block in halting'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:229:in `call'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:229:in `block in halting'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:229:in `call'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:229:in `block in halting'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `call'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `block in halting'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `call'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `block in halting'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `call'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `block in halting'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:86:in `call'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:86:in `run_callbacks'
vendor/bundler/gems/actionpack-4.1.1/lib/abstract_controller/callbacks.rb:19:in `process_action'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/rescue.rb:29:in `process_action'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/notifications.rb:159:in `block in instrument'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/notifications.rb:159:in `instrument'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
vendor/bundler/gems/activerecord-4.1.1/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
vendor/bundler/gems/actionpack-4.1.1/lib/abstract_controller/base.rb:136:in `process'
vendor/bundler/gems/actionview-4.1.1/lib/action_view/rendering.rb:30:in `process'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal.rb:195:in `dispatch'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
vendor/bundler/gems/actionpack-4.1.1/lib/action_controller/metal.rb:231:in `block in action'
vendor/bundler/gems/actionpack-4.1.1/lib/action_dispatch/routing/route_set.rb:80:in `call'
vendor/bundler/gems/actionpack-4.1.1/lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
vendor/bundler/gems/actionpack-4.1.1/lib/action_dispatch/routing/route_set.rb:48:in `call'
vendor/bundler/gems/actionpack-4.1.1/lib/action_dispatch/journey/router.rb:71:in `block in call'
vendor/bundler/gems/actionpack-4.1.1/lib/action_dispatch/journey/router.rb:59:in `each'
vendor/bundler/gems/actionpack-4.1.1/lib/action_dispatch/journey/router.rb:59:in `call'
vendor/bundler/gems/actionpack-4.1.1/lib/action_dispatch/routing/route_set.rb:676:in `call'
vendor/bundler/gems/omniauth-1.2.1/lib/omniauth/strategy.rb:186:in `call!'
vendor/bundler/gems/omniauth-1.2.1/lib/omniauth/strategy.rb:164:in `call'
vendor/bundler/gems/omniauth-1.2.1/lib/omniauth/builder.rb:59:in `call'
vendor/bundler/gems/warden-1.2.3/lib/warden/manager.rb:35:in `block in call'
vendor/bundler/gems/warden-1.2.3/lib/warden/manager.rb:34:in `catch'
vendor/bundler/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call'
vendor/bundler/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
vendor/bundler/gems/rack-1.5.2/lib/rack/conditionalget.rb:25:in `call'
vendor/bundler/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
vendor/bundler/gems/actionpack-4.1.1/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
vendor/bundler/gems/actionpack-4.1.1/lib/action_dispatch/middleware/flash.rb:254:in `call'
vendor/bundler/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
vendor/bundler/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
vendor/bundler/gems/actionpack-4.1.1/lib/action_dispatch/middleware/cookies.rb:560:in `call'
vendor/bundler/gems/activerecord-4.1.1/lib/active_record/query_cache.rb:36:in `call'
vendor/bundler/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
vendor/bundler/gems/activerecord-4.1.1/lib/active_record/migration.rb:380:in `call'
vendor/bundler/gems/actionpack-4.1.1/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:82:in `run_callbacks'
vendor/bundler/gems/actionpack-4.1.1/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
vendor/bundler/gems/actionpack-4.1.1/lib/action_dispatch/middleware/reloader.rb:73:in `call'
vendor/bundler/gems/actionpack-4.1.1/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
vendor/bundler/gems/actionpack-4.1.1/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
vendor/bundler/gems/actionpack-4.1.1/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
vendor/bundler/gems/railties-4.1.1/lib/rails/rack/logger.rb:38:in `call_app'
vendor/bundler/gems/railties-4.1.1/lib/rails/rack/logger.rb:20:in `block in call'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/tagged_logging.rb:68:in `block in tagged'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/tagged_logging.rb:26:in `tagged'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/tagged_logging.rb:68:in `tagged'
vendor/bundler/gems/railties-4.1.1/lib/rails/rack/logger.rb:20:in `call'
vendor/bundler/gems/quiet_assets-1.0.2/lib/quiet_assets.rb:18:in `call_with_quiet_assets'
vendor/bundler/gems/actionpack-4.1.1/lib/action_dispatch/middleware/request_id.rb:21:in `call'
vendor/bundler/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
vendor/bundler/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
vendor/bundler/gems/activesupport-4.1.1/lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
vendor/bundler/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
vendor/bundler/gems/actionpack-4.1.1/lib/action_dispatch/middleware/static.rb:64:in `call'
vendor/bundler/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
vendor/bundler/gems/railties-4.1.1/lib/rails/engine.rb:514:in `call'
vendor/bundler/gems/railties-4.1.1/lib/rails/application.rb:144:in `call'
vendor/bundler/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
vendor/bundler/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
vendor/bundler/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
~/.rbenv/versions/2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
~/.rbenv/versions/2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
~/.rbenv/versions/2.1.1/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
vendor/bundler/gems/logging-1.8.2/lib/logging/diagnostic_context.rb:323:in `call'
vendor/bundler/gems/logging-1.8.2/lib/logging/diagnostic_context.rb:323:in `block in create_with_logging_context'

@skuridin
Copy link

@Lordnibbler same problem =(

@bamorim
Copy link
Contributor

bamorim commented Jun 13, 2014

+1 for this. I'm having the same problem.

@dgellow
Copy link

dgellow commented Jun 16, 2014

Same probleme here.

# movie_option.rb
class MovieOption < ActiveRecord::Base
  has_and_belongs_to_many :movies
end
# movie.rb
class Movie < ActiveRecord::Base
  has_and_belongs_to_many :options, class_name: 'MovieOption'
  #...
end
# error
undefined method `movies_options_id_eq' for Ransack::Search<class: Movie, base: Grouping <combinator: and>>:Ransack::Search

@jufemaiz
Copy link

@dgellow just a dumb question, but could you possibly go with the following to move away from a HABTM approach?

# movie.rb
class Movie < ActiveRecord::Base
  has_many :movie_options
  has_many :options, through: :movie_options
  #...
end
# option.rb
class Option < ActiveRecord::Base
  has_many :movie_options
  has_many :movies, through: :movie_options
  #...
end
# movie_option.rb
class MovieOption < ActiveRecord::Base
  belongs_to :movie
  belongs_to :options
  #...
end

And then leave in the ID column in the movie_options table? This would ensure that the id_eq responds correctly, and also allow you to add any additional metadata you'd like to the movie_option entry that joins the two entries.

@rcstamato
Copy link

I am having the same problem with a HABTM. Any news on that?

@fredoliveira
Copy link

+1 - having the same issue with HABTM relationships. For every model that has one, rendering the page fails.

@MicFin
Copy link

MicFin commented Jul 3, 2014

+1 also having same problem on gem 'activeadmin', github: 'gregbell/active_admin'

@wild5r
Copy link

wild5r commented Jul 6, 2014

look like the problem is appear only with rails-4.1.1, versions rails-4.0.8 and rails 4.1.2+ work fine for me. Using ransack-1.2.3

difference between result ActiveAdmin.application.namespaces[:admin].resources[:Profile].filters

4.0.8

{:profiles_items=>{}, :items=>{}, :slug=>{}, :first_name=>{}, :last_name=>{}, :completed=>{}, :created_at=>{}, :updated_at=>{}}

4.1.1:

{:items=>{}, :slug=>{}, :first_name=>{}, :last_name=>{}, :completed=>{}, :created_at=>{}, :updated_at=>{}}

look like "profiles_items" is excess
and useful hack for version 4.1.1 is:

# in resource code
config.filters.each {|name,value| remove_filter(name) if name.match /#{config.resource_table_name.gsub('"','')}_*/ }

P.S with rails 4.1.2-4.1.4 active_admin filters work fine, but thinking_sphinx have a problem with HABTM relations

@jufemaiz
Copy link

jufemaiz commented Jul 7, 2014

Hi there Greg. I saw the problem in Rails 4.0.5

What was the version of Ransack::Search in the two above instances?

On 6 July 2014 18:26, wild notifications@github.com wrote:

look like the problem is appear only with rails-4.1.1, versions
rails-4.0.8 and rails 4.1.2+ work fine for me.

difference between result
ActiveAdmin.application.namespaces[:admin].resources[:Profile].filters

4.0.8

{:profiles_items=>{}, :items=>{}, :slug=>{}, :first_name=>{}, :last_name=>{}, :completed=>{}, :created_at=>{}, :updated_at=>{}}

4.1.1:

{:items=>{}, :slug=>{}, :first_name=>{}, :last_name=>{}, :completed=>{}, :created_at=>{}, :updated_at=>{}}

look like "profiles_items" is excess
and useful hack for version 4.1.1 is:

in resource codeconfig.filters.each {|name,value| remove_filter(name) if name.match /#{config.resource_table_name.gsub('"','')}_*/ }

P.S with rails 4.1.2-4.1.4 active_admin filters work fine, but
thinking_sphinx have a problem with HABTM relations


Reply to this email directly or view it on GitHub
#2565 (comment)
.


Joel Courtney
m: +61 401 501 625
e: euphemize@gmail.com
w: http://euphemize.net
p: http://flic.kr/jufemaiz/

t: http://twitter.com/jufemaiz

@chibicode
Copy link

Same problem here as of revision 2736099 with rails 4.1.4. Did a workaround as specified on #2565 (comment)

@seanlinsley seanlinsley added this to the 1.0.0 milestone Jul 28, 2014
@jonmarinello
Copy link

I'm also running into this. Is anyone working on a fix? Looks like it will be included in 1.0.0. Is that correct and if so when will that become available? Looks like its 5 months past due.

@jonmarinello
Copy link

BTW - I don't know if any of you have stumbled on to this before but just defining the filter fixes the problem. Just found that out by experimenting more.

@tmclark737
Copy link

Hi,

Thanks in advance for any help. I am getting an error when using active admin in my 'rails 4.1.4' application. This model does not have any associations. Has anyone encountered this before? Thanks again!

Error:
NoMethodError at /admin/time_tables
undefined method `w_day_start' for #Ransack::Search:0x00000008fcbc70

Model:
class TimeTable < ActiveRecord::Base
end

Schema:
create_table "time_tables", force: true do |t|
t.string "name"
t.datetime "w_day_start"
t.datetime "w_day_stop"
t.datetime "w_end_start"
t.datetime "w_end_stop"
t.text "note"
t.datetime "created_at"
t.datetime "updated_at"
end

@timoschilling
Copy link
Member

@tmclark737 ActiveAdmin / Ransack have a problem with columns that ends with start. You can try to disable all filters or the filters for the fields with start.

If that doesn't work, please open a new issue, I think that is not related to this one.

@tmclark737
Copy link

timoschilling! Thanks for the quick reply! I will try it out right now.

@timoschilling
Copy link
Member

Can someone that has this problem, please check that is still exists, with current ransack master?

@timoschilling
Copy link
Member

@tmclark737 ActiveAdmin should now work with filters that ends with start

@tmclark737
Copy link

Sweet! Thanks Timo. =)

On Thu, Nov 13, 2014 at 4:11 PM, Timo Schilling notifications@github.com
wrote:

@tmclark737 https://github.com/tmclark737 ActiveAdmin should now work
with filters that ends with start

Reply to this email directly or view it on GitHub
#2565 (comment)
.

Ty Clark PE
Bay Efficiency, LLC
Phone: (415) 730-2710
Email: Ty.Clark@BayEfficiency.com
http://www.linkedin.com/in/clarkty

@timoschilling
Copy link
Member

Ransack had some problems in the past, wich ends in error like:

undefined method `users_user_id_eq' for Ransack::Search<class: Detail, base: Grouping <combinator: and>>:Ransack::Search

While here is no activity since a while, I'm going to close this.

If someone has problems like this please open a new issue

@romainyakarouler
Copy link

thanks u @seanlinsley

@ronnyworm
Copy link

Ah, yeah we aren't correctly handling nested has_many :through relationships. For now, you can just remove that filter:

ActiveAdmin.register Detail do
  remove_filter :users
end

Thanks! For me it was remove_filter :user

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests