GithubHelp home page GithubHelp logo

Not using `present_params` about filterer HOT 2 CLOSED

ramontayag avatar ramontayag commented on August 31, 2024
Not using `present_params`

from filterer.

Comments (2)

olliebennett avatar olliebennett commented on August 31, 2024

Your issue seems to be two parts;

Filtering for empty string

I think (regardless of the implementation), a user may assume that leaving a blank field (empty string) would not filter on that field at all; i.e. if you leave "age" blank, you would not filter by "age" at all.

I use the keyword BLANK to indicate an explicit search for "" on a given field. My filter config therefore looks like this;

  def param_age(age_query)
    return @results.where(age: nil) if age_query == 'BLANK'

    @results.where(age: age_query)
  end

Filtering with two fields at once

This can be achieved by deferring the logic to only one of the methods, although it's a little ugly.

  def param_age(age_filter)
    return @results.none if params[:rank].blank?

    @results.where(age: age_filter, rank: params[:rank])
  end

  def param_rank(_)
    # ignored here as rank cannot be filtered in isolation; see param_age.
  end

Hope that helps with your use-case, at least?

from filterer.

ramontayag avatar ramontayag commented on August 31, 2024

Cool. I forgot about this! I'm no longer working on the project that needed this, and I'm not sure what I did. Cheers, and happy new year!

And yes, it does sound like what you put will solve it!

from filterer.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.