Implementing an ActiveRecord before_find

Posted by thaiyoshi on Stack Overflow See other posts from Stack Overflow or by thaiyoshi
Published on 2009-04-29T17:59:53Z Indexed on 2010/06/10 8:02 UTC
Read the original article Hit count: 145

Filed under:
|

I am building a search with the keywords cached in a table. Before a user-inputted keyword is looked up in the table, it is normalized. For example, some punctuation like '-' is removed and the casing is standardized. The normalized keyword is then used to find fetch the search results.

I am currently handling the normalization in the controller with a before_filter. I was wondering if there was a way to do this in the model instead. Something conceptually like a "before_find" callback would work although that wouldn't make sense on for an instance level.

© Stack Overflow or respective owner

Related posts about activerecord

Related posts about callbacks