开发者

Ruby on Rails: What to do when two models share a lot of similar validations/validation_methods

I have a co开发者_Python百科uple of models that are both "password" centric models. They don't belong in a single inheritance table and need to be tracked in separate tables. Logically they are both completely different types of models, but both have password and password confirmation tracking. They also use the same business logic for the password rules such as number of characters in the password etc.

What's the best way in Rails to make sure that the code is DRY and not being repeated in Rails? What should I look into doing?


Factor the common code out into a module, then include the module in each model class.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜