Andrzej Gis
Andrzej Gis

Reputation: 14306

Ruby/ROR disable a method

My question is related to ROR, but in fact it's rather about ruby syntax I think.

In a model there is a built in method 'save', which saves the model to a database. I need to override the method, to do some additional job concerning files. I overloaded the method with a new one which takes 2 arguments. What I want to do now is to disable the original save method, so I don't use it somewhere accidentally. For now I managed to do this by using alias_method. Now after calling save method with no arguments only prints a message to the console. The problem is this message probably will be overlooked.

What will be the best way to handle this? Bye

Upvotes: 1

Views: 204

Answers (1)

dnch
dnch

Reputation: 9605

Your best option is to use the before_save and after_save callbacks in Ruby on Rails.

You can read more about them here: http://guides.rubyonrails.org/active_record_validations_callbacks.html#callbacks-overview

Upvotes: 7

Related Questions