Joined May 2015
·
Posted to
Prevent updates on Rails models
over 1 year
ago
This was really helpful. However, I found that the default behaviour of just the readonly?
override example here was to prevent destroy
.
Here's the approach I took to re-enabling it whilst also making a side-route to explicitly allow an update
before_destroy :allow_next_update!
def allow_next_update!
@allow_update = true
end
def readonly?
if @allow_update
@allow_update = false
return false
end
return true unless new_record?
end
Posted to
Proc to search all tables for a specific piece of data.
over 1 year
ago
I should say, this is for SQL Server 2005 and later
Oh and actually
!new_record?
is a neater way of writingnew_record? ? false : true