Filip
Filip

Reputation: 346

Event system in rails

I am an experienced PHP developer and i am used with the event system in Laravel. Is there something similar in Rails? I like this concept very much and I am amazed that Rails does not have something like this by default. Or at least it is not in the documentation.

Upvotes: 2

Views: 283

Answers (1)

MarsAtomic
MarsAtomic

Reputation: 10673

Rails offers Active Record callbacks rather than an arbitrary event mechanism. These callbacks provide hooks around standard ReSTful actions that will take place during the lifecycle of an Active Record object.

Object Creation

before_validation
after_validation
before_save
around_save
before_create
around_create
after_create
after_save
after_commit/after_rollback

Object Update

before_validation
after_validation
before_save
around_save
before_update
around_update
after_update
after_save
after_commit/after_rollback

Object Destruction

before_destroy
around_destroy
after_destroy
after_commit/after_rollback

You can tie your own custom controller methods to any of these callbacks to have them run at specified points.

Read the official guide for more information.

Upvotes: 1

Related Questions