Reputation: 250
I need to find a way to track the specific moment in which a model attribute has changed from one state to another.
List
model with an attribute called
voting_status
, which can be either true
or false
.true
to false
, so that other users can start voting on it.voting_status
changes back and the
other users are not able to vote anymore, even though they did not get the chance to vote in the first place.if
statement that checks if a user voted between the moment the owner clicked the button and now by using another model I have called Vote
, which tracks the user that voted and the item which was voted.
vote = Vote.find_by(user_id: 4)
list = List.find(5)
if vote.created_at is_between list.voting_status_changed?(from: true, to: false).when..DateTime.now
user cannot vote
else
user can vote
end
when
method or something similar that can return the date in which the owner clicked that button, thus updating the attribute.Any ideas? Thank you.
Upvotes: 0
Views: 2441
Reputation: 9747
You will need to use one of the following gems to keep track of changes.
All the above mentioned gems will work for you
EDIT: I have not used but you can give a try to Public Activity Gem too.
Upvotes: 3
Reputation: 2289
There is Auditable Gem, that would do the trick for you. Though there are lots of others that have similar functuinality, see related section https://www.ruby-toolbox.com/projects/auditable
Upvotes: 0