开发者

A way to handle common behaviors

开发者 https://www.devze.com 2023-03-17 01:13 出处:网络
I am using Ruby on Rails 3.0.7 and I have multiple resources that almost have the same behavior. That is, those almost have same model, controller and view codes and same database table columns defini

I am using Ruby on Rails 3.0.7 and I have multiple resources that almost have the same behavior. That is, those almost have same model, controller and view codes and same database table columns definition.

So I would like to find a way to DRY those resources. I already implemented modules and mixins for those in order to share part of the code (as validation methods, callbacks, view files but not controller files that, anyway, have very similar code).

Now, how ca开发者_运维百科n I do to handle this common behavior? Should I use something that Ruby on Rails developers named as acts_as_something? What do you advice about?


I think you already did that, just name a method in your modules act_as_your_module_name and make sure your module extends from your Base Class, e.g. ActiveRecord::Base.extend act_as_your_module_name

http://www.cowboycoded.com/tag/acts_as/

0

精彩评论

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