person = Person.new
person.name = "John"
Will cause a new row to be inserted into database. But I don't want it
to be saved into DB, instead when "save!" method is called I want to
connect to a particular URL and post data to it.
"name" => "John"
I need this because I don't have write access to my DB.
The obvious way to do it is override save, save!, create and delete
methods. but I wonder if there is more convenient way to do it.
If you need to do all interactions with your persistence layer via http,
this is a job for ActiveResource, not ActiveRecord.
If you just need to override the save method, then you can monkeypatch
by overriding the create_or_update method:
class Person < ActiveRecord::Base
# do what you need to do here
Just make sure that you check the rails code for create_or_update so
that you know what functionality you're replacing, so that your new
method will do what it is supposed to without breaking other save calls.