Reputation: 3890
When you define an association in Rails, it creates some methods on that association for you. For example, consider the following:
class Person
has_many :friends
end
One of the methods you get is person.friends.clear
How can I remove this method such that person.friends.clear
would raise a NoMethodError
?
Note: I have tried a few things, including undef_method
and remove_method
without luck. Please only provide known answers and not guesses.
Upvotes: 1
Views: 110
Reputation: 5317
Though I didnt try it myself but could would pls check if the following works
has_many :friends do
def clear
raise NoMethodError, "Some reason text"
end
end
Upvotes: 2