美文网首页
把常用的find写入model

把常用的find写入model

作者: Kjiang | 来源:发表于2015-11-29 18:40 被阅读15次

对于一些比较常用的find查询,我们应该写入model中,以降低重复工作和方便日后维护修改。

class Task < ActiveRecord::Base
  belongs_to :project

  def self.find_incomplete
    find_all_by_complete(:false, order: "created_at DESC")
  end

那么我们在controller中就可以直接这么用:

@tasks = Task.find_incomplete

于2015-03-20

相关文章

网友评论

      本文标题:把常用的find写入model

      本文链接:https://www.haomeiwen.com/subject/myqjhttx.html