Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 973
Eric Lavoie Avatar asked Feb 11 '14 16:02

Eric Lavoie


1 Answers

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

like image 144
Eric Lavoie Avatar answered Oct 14 '22 18:10

Eric Lavoie