views:

32

answers:

1

Lets say I have a food model

in the model, every day, people enter how many lbs of pizza/vegetables/fruit they eat.

each food is its own column

my issue is, I'd like it so they can only enter that in once (for that food type) every 24 hours (based on created_at).

This possible?

A: 

I don't think it is possible using the standard rails validations, but it should be easy to build your own.

I would start by building a named scope that finds entries on a given day.

Then, in your validates you can use the exists? method to find see if there are any records that already exist that would conflict. Keep in mind that the exists? method will detect the current record by default, so you will have to account for that.

Mike Dotterer