Who knows ransack?

I’m using ransack for my searches.
I need to search through date fields but only for year.
For example I need all documents created in 2011.
For those that use ransack, there such a way to do this?

On 19 October 2011 17:04, PsiPro [email protected] wrote:

I have used ransack, but what you are looking for is not directly
implemented.

You have two options:

  1. Use a database specific syntax such as EXTRACT

I have a form like this:

= simple_form_for @q, :url => unsafe_buildings_path, :html => {:method
=> :get} do |f|
.block
.column.span-11
.inputs
= f.label :practice_number_eq, t(‘practice_number’)
= f.input :practice_number_eq, :label => false, :required =>
false
= f.label :property_cont, t(‘property’)
= f.input :property_cont, :label => false, :required => false
= f.label :practice_date_in, t(‘practice_date’)
= f.input :practice_date_in, :as => :date, :label => false,
:required => false,
:start_year => Settings.unsafe_buildings_start_year,
:include_blank => true
= f.button :submit, “Cerca”

I want to search also for practice_date where based on year.
I’m using postgres as db.
How can I integrate “extract” in this form?

I have used ransack, but what you are looking for is not directly
implemented.

You have two options:

  1. Use a database specific syntax such as EXTRACT
  2. Create a predicate (see github readme) which will which that the
    date is greater then or eq to 1/1/2011 00:00:00 and less then 1/1/2012
    00:00:00

You can see the built-in predicates here:
https://github.com/ernie/ransack/blob/master/lib/ransack/constants.rb

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