首页 > 其他 > 详细

model特性

时间:2016-11-19 13:23:06      阅读:100      评论:0      收藏:0      [点我收藏+]
1.scope
http://blog.csdn.net/lissdy/article/details/51107883

2.ActiveConcern
http://www.tuicool.com/articles/7jIzEbe

 included do |base|  #这里的base参数代表的是include该module的class   这篇文章当中的这句话是:base指的是宿主
        scope :active, -> {where(is_active: true)}
     end

https://ruby-china.org/topics/19812

include 添加实例方法  extend 类方法

3.delegate
http://www.cnblogs.com/orez88/articles/1717438.html


4.model重构
https://github.com/zlx/useful_article/blob/master/best_practices/7_patterns_to_refactor_fat_ActiveRecord_Models.md
英文版http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/


scope  model中预先定义一个查询方法
concern  重复的部分抽成一个module
delegate  选择继承一个model中的一部分方法(只看的model中的,不知道其他的怎么用todo)

 

model特性

原文:http://www.cnblogs.com/znsongshu/p/6080194.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!