Aamir
Aamir

Reputation: 5440

Before filter for models in a Sinatra application

I am using Sinatra and have organized my application into models, views and routes (as suggested here).

I have come across several guides (such as Sinatra Book) on using before filters with routes. Is there any way to use before filters for models?

I am using the Sinatra ActiveRecord extension if it helps.

Upvotes: 0

Views: 513

Answers (1)

Daniel Vartanov
Daniel Vartanov

Reputation: 3277

ActiveRecord has such before filters out-of-the-box. It supports before_save, after_save, before_create, after_create, and even before_validation and after_validation.

Look here for a detailed explanation: http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

Upvotes: 1

Related Questions