1

According to all the documentation and tutorials I've found, defining the following method in my ActiveRecord subclass (AuthenticationToken) should prevent saving changes to an existing record, but not prevent it from being created or destroyed:

def readonly?
    !new_record?
end

However, calling token.destroy throws "AuthenticationToken is marked as readonly". For now I am using token.delete, which is acceptable because the model has no children, but I'd like to be able to use destroy. I'm using Rails 4.2.5.

TWGerard
  • 885
  • 1
  • 10
  • 24

2 Answers2

0

I think adding

before_destroy { true }

would allow you to destroy the object.

Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145
0

Use delete instead, it will be able to delete records marked as readonly

Lane
  • 685
  • 2
  • 10
  • 25