码迷,mamicode.com
首页 > 其他好文 > 详细

model特性

时间:2016-11-19 13:24:53      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:tail   nbsp   ast   选择   重构   特性   practice   https   module   

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特性

标签:tail   nbsp   ast   选择   重构   特性   practice   https   module   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!