#119 new
Nick Clarke

Unable to get conditional columns working

Reported by Nick Clarke | February 26th, 2010 @ 10:24 AM

Hi

I'm just starting to use searchlogic and all was going fine until I needed a column to be a value or blank. I have a search box that passes in designer and size or nothing is the user simply leaves them blank and hits search.

I originally had this:

Shoe.size_equals(params[:size]).designer_name_equals(params[:designer])

This worked fine but I could not work out how to get it to work if they only selected the designer and not the size.

I noticed in the doc that you can use or on the columns names (User.username_or_first_name_like) but I need it on the values and not the columns.

I then tried converting my code to use the search method:

@s = Shoe.search

if params[:size]
    @s.size_equals = params[:size]
end

if params[:designer]
    @s.designer_name_equals(params[:designer])
end

@s.all

This errors with:

-->wrong number of arguments (0 for 1) `search'

So tried using the parent class but I now get a different error:

@s = Item.search

--> undefined method `designer_name_equals' for #<Class:0x6b566b0>

Maybe I'm simple using it wrong or missing a mapping so any pointers will be great.

Thanks in advance,
Nick

Rails 2.3.5 with searchlogic 2.4.11

class Item < ActiveRecord::Base
end

class Shoe < Item
  belongs_to :designer
  #size
end

class Designer < ActiveRecord::Base
  validates_presence_of :name
  has_many :shoes

  attr_accessible :name
end

No comments found

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Provides common named scopes and object based searching.

People watching this ticket

Pages