Search and filter problems

2,297 views
Skip to first unread message

Nick Roosevelt

unread,
Jun 20, 2012, 3:17:18 AM6/20/12
to rails...@googlegroups.com
I have an app with rails 3.1.3 and rails_admin.  I can not seem to get it to do searching with the associations.  Is anyone else having any similar problem?  I have spent many hours trying many things.  I can get the filtering working, but the search will only search the main table's fields.  Does this sound at all familiar to anyone?

Thanks,

Nick

Steph Skardal

unread,
Jun 25, 2012, 11:10:40 AM6/25/12
to rails...@googlegroups.com
On 06/20/2012 03:17 AM, Nick Roosevelt wrote:
I have an app with rails 3.1.3 and rails_admin.  I can not seem to get it to do searching with the associations.  Is anyone else having any similar problem?  I have spent many hours trying many things.  I can get the filtering working, but the search will only search the main table's fields.  Does this sound at all familiar to anyone?

Hi Nick,

Yes, I just came across this and did some debugging to see what the cause is. By default, the searchable field is the referencing field only (e.g. abstract_model_table.association_name_id). The searchable fields are configurable, so you can add something similar to the following in your list method in the config:

config.model do ParentModelName do
  list do
    field :association do
      searchable [:association_field2, :association_field2]
    end
  end
end

The wiki covers this here (with an example): https://github.com/sferik/rails_admin/wiki/List in the Fields searching section.

~Steph

-- 
Steph Skardal
End Point, Corp

ph: 336-245-8807
st...@endpoint.com

Nick Roosevelt

unread,
Jun 25, 2012, 9:37:53 PM6/25/12
to rails...@googlegroups.com
I have read the wiki.  I have read the code.  I have tried all the ways to configure it that I could find, including the way you list (but I think you mean "searchable [:association_field1, :association_field2]" - changing the first 2 for a 1.  When I configure the associated fields, the code that I think adds the search configuration (rails_admin/config/fields/base.rb lines 73 to 104) does not seem to run - I have tried putting "debugger" statements and print statements (though it does seem to run for the primary model fields.  I can't figure out where in between my code and the code that does the configuration that the flow control is getting stopped.  I don't really fully understand how all that meta-code works.  Can anyone point me in some direction that allows me to find what is going wrong?  Is there something special I need to do in the model(s)?  It does do the sorting, and it does display it, but it does not set it up for searching.

--
You received this message because you are subscribed to the Google Groups "rails_admin" group.
To post to this group, send email to rails...@googlegroups.com.
To unsubscribe from this group, send email to rails_admin...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rails_admin?hl=en.

Nick Roosevelt

unread,
Oct 22, 2013, 5:50:45 PM10/22/13
to rails...@googlegroups.com
Well, someone tweeted me about this, so I am coming back to post what we are doing...

We have a bunch of stuff like this:

    field(:corporation) do
      searchable [{Corporation => :name}]
      queryable true
    end

Mark Silverberg

unread,
Oct 22, 2013, 5:58:47 PM10/22/13
to rails...@googlegroups.com
Nick - thanks for posting. Does the model this field block is in have a has_one, has_many, or what kind of association? just tried with a has_one and get the following error:

PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "X"
LINE 1: ...a_items"."Y" WHERE ('t'='t') AND ((LOWER(X.emai...

Mark Silverberg

unread,
Oct 22, 2013, 6:05:35 PM10/22/13
to rails...@googlegroups.com
Oh, looks like it is a has_one through. Let me try with a regular has_one.

Mark Silverberg

unread,
Oct 24, 2013, 2:27:34 PM10/24/13
to rails...@googlegroups.com
I was able to "hack" this to work the way I want using a combination of Nick's field configuration and patching the RailsAdmin's MainController#get_collection first line to read as `associations = model_config.list.fields.select {|f| (f.type == :belongs_to_association || f.type == :has_one_association ) && !f.polRails conf_in: developmentymorphic? }.map {|f| f.association[:name] }` 

Feel free to contact me if you need 1:1 help. I will try to figure out how to monkey patch this and add it to the wiki but for now, I am overriding MainController in my app.

Mark
Reply all
Reply to author
Forward
0 new messages