I am trying to build a filter area on my index with multiple parameters. My problem is that I don't know how to make each of them optional if I need to. I mean, even if I don't set a value to a field, I want my filter to only work with the ones I filled.
I wrote this code which works well, except when I remove one or several parameters.
def self.filter(type, min, max, start_at, end_at)
where(type => min..max, :first_date => start_at..end_at).order("#{type}": :desc)
end
I know I can use scope but as I am new to Rails, it's pretty unclear. If somebody can come with some hints? Thanks!