In my app I have note.rb
with the schema shown below. What I am trying to do is restrict the ability to edit notes. Basically if the note has been created in the last 24 hours, you are allowed to update whatever you want. After 24 hours, all you can do is change the remind_at
time. I have a method in the note.rb
file that checks if the note is editable. If it is I display different partials. But that only restricts the front end, if someone has left the edit window open, or types in the URL, they can still edit the note after 24 hours.
What I am attempting to do is write a before_update
method that checks if you are allowed to update the body
of the note or not. No matter what you can update the remind_at
time. Part of the problem is that the way the controller knows whether or not this is simply a change to the remind_at
time is via params[:reschedule]
and params
are not accessible in the model.
# == Schema Information
#
# Table name: notes
#
# id :integer not null, primary key
# body :text
# remind_at :datetime
# created_at :datetime
# updated_at :datetime
# Only allow editing of notes that are less that 1 day old
def editable?
self.created_at > (Time.now-1.day)
end