Default search

3 views
Skip to first unread message

Charley

unread,
Dec 29, 2009, 11:05:34 AM12/29/09
to Searchlogic
I followed the rails cast to make a search for my table and it works
perfectly. The table involves a list of To Do List items and want to
customize it a little and am running into trouble. What I want to do
is use the current search that I have, but before the search is
performed have default the list to display all the items whose
completed status is false instead of return all rows. Here is my
current controller logic that returns all rows:

@search = Todolist.search(params[:search])
@todolists = @search.all

I tried the following code, but had no luck:

if params[:search].blank?
@search = Todolist.search(completed = false)
@todolists = @search.all

else
@search = Todolist.search(params[:search])
@todolists = @search.all
end

If anybody has any suggestions, I would greatly appreciate your help.

-Charley

Ben Johnson

unread,
Jan 7, 2010, 3:59:41 AM1/7/10
to searc...@googlegroups.com
Hi Charley,

I typically just do:

@search.my_conditions ||= "my default value"
@search.all

Hope that helps

Ben Johnson
Binary Logic

W: www.binarylogic.com
E: bjoh...@binarylogic.com

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

Reply all
Reply to author
Forward
0 new messages