简体   繁体   中英

Ruby on Rails filterrific gem simple filter

I'm new to Ruby on Rails and currently trying to set up an easy search with filterrific. But all examples I can find are much more complicated then mine and I'm a bit confused:

I have a model where I store Bank Holidays. I want to filter the output so the user just sees one year, should default to current year.

Therefore I created a scope in my model:

  selected_year = Date.today.year
  scope :year, -> {
  where("YEAR(holiday_date) = #{selected_year}")
  }

All examples for filterrific have found exspect that a user wants to search matching different values in related databases.

Any hint on how to filter just simple one value?

Thanks Simon

It looks like you want to allow the scope to receive an argument like so

scope :year, ->(year) { where("YEAR(holiday_date) = #{year}") }

Then you can call Model.year(1986) etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM