I have been struggling with a Client request to filter out A model(Candidate) on the basis of Column Format
The issue I am facing is that column inputs either SSN or EIN. The format for SSN is (xxx-xx-xxxx) The format for EIN is (xx-xxxxxxx)
My candidates Table contains the field ssn_or_ein , which takes either one of these 2.
For ex: candidate111.ssn_or_ein => 111-11-1111 candidate222.ssn_or_ein => 22-2222222
I have tried fetching all the 4000 accounts, but i suppose that's not how a developer's approach should be.
I am still learning Rails and any tip would be really helpful.
You can do this with a like query. Put it in a scope so it's easily available.
However, this can get slow if
ssn_or_einis not properly indexed.Consider storing them in two different columns. This makes validation and querying simpler. Bring them together only when you just need a TIN - Taxpayer Information Number.
I would also suggest that you store the data "normalized", without the dashes, just the numbers. This is simpler to work with, and the accepted format can be changed without having to change all the data. Format them in a decorator.