Controller Search Strategy

I’m trying to create a search action for one of my controllers that
can take in different params. Something I can use like an api call:

…/users/search?first_name=john&org_id=1

Any idea how I can start this? I’d like to have a clean “search”
action but this is also copying the index action. I’m thinking that
the action needs to serialize the params and apply them to a find but
I’m not sure if this is the best way.

Thanks.

sshefer wrote:

I’m trying to create a search action for one of my controllers that
can take in different params. Something I can use like an api call:

…/users/search?first_name=john&org_id=1

Any idea how I can start this? I’d like to have a clean “search”
action but this is also copying the index action. I’m thinking that
the action needs to serialize the params and apply them to a find but
I’m not sure if this is the best way.

Thanks.

Have you looked at searchlogic?

http://github.com/binarylogic/searchlogic

Sounds exactly what you are looking for.

Cheers
Luke

Shai S. wrote:

Hey Luke,

Yeah - I’ve used search logic in the past. I’m trying to make search
calls
using ajax requests and as I understand it I can’t do that with search
logic
(I may be wrong).

Take what I say with a grain of salt, as I haven’t actually used
Searchlogic… but as I understand it it basically just extends
ActiveRecord to automagically add a bunch of convenience named scopes,
and automatically uses those named scopes when you call search on the
the model’s class? It really doesn’t mess with ActionController or
ActionView at all besides adding a couple helper methods, so I can’t see
how it makes ajax anymore difficult. Have you actually tried using
Searchlogic with ajax and encountered problems? If so, what were they?

Hey Luke,

Yeah - I’ve used search logic in the past. I’m trying to make search
calls
using ajax requests and as I understand it I can’t do that with search
logic
(I may be wrong).

Hi Paul,

I think you’re right - I took a second look at searchlogic (I haven’t
used
it for more than a year) and you can pass your search paramaters in the
url
pretty cleanly
(search?searchhttp://www.google.com/url?sa=D&q=http://localhost:3000/activities/search%3Fsearch&usg=AFQjCNH06twZNMzjAxjE2ctwuV_8X6BIkQ[order]=&search[created_by_id_equals]=30&search[hidden]=1).
I thought there was some method that would take an encoded url and
decode
it into the search params but you can just use it directly. My mistake.

Searchlogic it is! (Thanks Luke)

Thanks,

Shai

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs