开发者

before_find callback in ruby on rails 3

My model has a string field, which actually used to store set of words. The order of the words is not important, so I use before_create callback to sort the words for uniqueness of the sets. Consequently I need corresponding callback for searching finding the string, i.e. such a callback would sort w开发者_StackOverflowords in the incoming string and perform regular search. There is built-in after_find callback, but no before_ counterpart.

What is the best way to implement it? It should be triggered by the same methods as after_find. Or maybe there is another solution instead of callback?

UPDATE: there is a similar question Implementing an ActiveRecord before_find, but I decided to sort the words in the controller before storing in the database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜