I am using Rails 3.0 and have several models which have a public, English, reference field such as a title on a chapter of a story. I am looking for an elegant way to implement certain stop words for actions on controllers, e.g. “new”, “update”, “destroy”, etc. What is the best way to do this, via some kind of callback during the saving of the model?
Share
Rails has a tonne of callbacks for exactly this kind of thing. I think the callbacks that would be of most interest to you would be before_validation, before_validation_on_create, after_validation and after_validation_on_create since you can get in a strip out stopwords and then have your validations run on whats left.
So your Chapter model would have something like:
The usual before_destroy and before_update are also there if you need them.