I have a model in Rails called Statistics and every time someone visits my page, I log their IP in the model and save. This is how my model currently looks:
Statistics(id: integer, ip: string, ...);
An example record return would be:
#<Statistics id: 700, ip: "10.0.2.2", ...>
But when I enter the Rails Console, and try to locate the record:
ruby-1.9.2-p290 :175 > Statistics.find_all_by_ip("10.0.2.2")
Statistics Load (0.8ms) SELECT "statistics".* FROM "statistics" WHERE "statistics"."ip" = '10.0.2.2'
=> []
I always get an empty return..
Are they any quirks to Rails for IP addresses that I don’t know of? I just can’t seem to figure out why this wouldn’t work.
My first assumption is that the IP address was stored using the value from an
Addrinfo, whereas SQLite uses UTF. This assumes you’re using SQLite, which you don’t mention.See my previous answer I gave covering this in some detail.