Joined May 2015
·

Adam

London
·
·

Posted to Prevent updates on Rails models over 1 year ago

Oh and actually !new_record? is a neater way of writing new_record? ? false : true

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

I should say, this is for SQL Server 2005 and later

Achievements
6 Karma
1,165 Total ProTip Views
Interests & Skills