How to fix Ransack undefined method "_eq", when using ActiveAdmin with ":through" relationships in your model?
Asked Answered
L

1

9

I have a Rails 4.0.1 application, using gems activeadmin 1.0.0.pre and ransack 1.1.0.

Using ActiveAdmin, I have many errors like this one :

NoMethodError in Admin::MyModel#action
Showing [...]/views/active_admin/resource/action.html.arb where line #1 raised:

undefined method `applied_boundaries_id_eq' for #<Ransack::Search:0x0..>
Extracted source (around line #1): insert_tag renderer_for(:index)

There is a pattern "_eq" for each undefined method :

aws_instance_type_clients_id_eq
user_roles_id_eq

Any idea ?

Langill answered 11/2, 2014 at 16:50 Comment(0)
L
15

I found the answer right here : undefined method `users_user_id_eq' for Ransack::Search

There is also a post here : weird error popped up with active admin that looks to be the same problem description.

It seems that Ransack (used by ActiveAdmin) do not like has many .. :through relationships.

Example :

If you have a user.rb that has many :roles, :through => :user_roles

This will give you the error : undefined method user_roles_id_eq

To fix (not really fix.. but avoid to get an error) the bug, edit your "ActiveAdmin.register User" file, and add : remove_filter :user_roles

Langill answered 11/2, 2014 at 17:3 Comment(1)
At the time (few years) I was unable to truly fix it.Langill

© 2022 - 2024 — McMap. All rights reserved.