Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

how to use a scope for the search ? #156

Closed
luisfernandos opened this Issue Oct 31, 2012 · 3 comments

Comments

Projects
None yet
3 participants

I am updating a rails application that uses searchlogic to ransack and I need some help to create predicates. I have this 2 scopes for getting a date interval for bdays, here they are:

scope :date_of_birth_gte, lambda {|d|
d1 = Date.strptime(d,I18n.t("date.formats.default"))
{
:conditions=>["RIGHT(date_of_birth,5) >= '#{"%02d" % d1.month}-#{"%02d" % d1.day}' and date_of_birth IS NOT NULL"]
}
}

scope :date_of_birth_lte, lambda {|d|
  d1 = Date.strptime(d,I18n.t("date.formats.default"))
  {
          :conditions=>["RIGHT(date_of_birth,5) <= '#{"%02d" % d1.month}-#{"%02d" % d1.day}'  and date_of_birth IS NOT NULL"]
  }
}

How can I enable ransack use such scopes. It would help a lot if somebody point some documentation; seems I need to do something in the configuration and in the model, however I have no idea from where I can start.
Any help would be appreciated.
Thanks a lot

I am using meta_search, so far so good

Member

jonatack commented Aug 29, 2014

There are code examples in the Ransack wiki, Ransackers section, that show how to do this.
Additionally, searching by scopes was added to Ransack in June.
Closing this for now.

@jonatack jonatack closed this Aug 29, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment