`
CaiDeHen
  • 浏览: 94304 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

#4 Move Find into Model

UP 
阅读更多
Move a find into the model to clean up the controllers and remove duplication. Also see how you can call these custom find methods through an association.

# tasks_controller.rb
def index
  @tasks = Task.find_incomplete
end

# models/task.rb
def self.find_incomplete
  find_all_by_complete(false, :order => 'created_at DESC')
end

# projects_controller.rb
def show
  @project = Project.find(params[:id])
  @tasks = @project.tasks.find_incomplete
end
分享到:
评论

相关推荐

    Xcode 4 Unleashed 2nd Edition (epub 格式)

    Through practical examples, he shows experienced Apple developers how to move to Xcode 4’s “browser” model from older document-based approaches. You’ll also find thorough, up-to-the-minute ...

    a project model for the FreeBSD Project.7z

    4 Methodology model 4.1. Development model 4.2. Release branches 4.3. Model summary 5 Hats 5.1. General Hats 5.1.1. Contributor 5.1.2. Committer 5.1.3. Core Team 5.1.4. Maintainership 5.2. Official ...

    AI_01_sfuadsadad

    2. **Search**: Search algorithms are fundamental to AI, enabling machines to find solutions to problems by exploring possible states or actions. Techniques such as breadth-first search, depth-first ...

    iOS.Application.Security

    You'l learn about: The iOS security model and the limits of its built-in protections The myriad ways sensitive data can leak into places it shouldn't, such as through the pasteboard How to implement ...

    kgb档案压缩console版+源码

    The data is compressed as if all the files were concatenated into one long string. PAQ6 uses predictive arithmetic coding. The string, y, is compressed by representing it as a base 256 number, x, ...

    IOS 10 Programming Fundamentals with Swift: Swift, Xcode, and Cocoa Basic

    Move into iOS development by getting a firm grasp of its fundamentals, including the Xcode IDE, the Cocoa Touch framework, and Swift 3 the latest version of Apple s acclaimed programming language....

    iOS 9 Programming Fundamentals with Swift 无水印pdf 0分

    Move into iOS development by getting a firm grasp of its fundamentals, including the Xcode IDE, the Cocoa Touch framework, and Swift 2.0—the latest version of Apple's acclaimed programming language....

    Test-Driven iOS Development with Swift

    ISBN: 178588073X | 2016 | True PDF | 218 pages | 4 MB Test-driven development (TDD) is a proven way to find software bugs early. Writing tests before your code improves the structure and ...

    网络协议攻击

    application protocol into flexible layers and abstracts complex technical detail, allowing you to focus on the bespoke parts of the protocol you’re analyzing. Chapter 2: Capturing Application Traffic...

    React and React Native [Kindle Edition]

    We then move on to showing you how to take the concepts of React and apply them to building Native UIs using React Native. You'll find out how to build responsive and streamlined UIs that can properly...

    The.Agile.Consultant.Guiding.Clients.to.Enterprise.Agility.epub

    Many organizations have brought in agile coaches and achieved great progress in software development productivity, only to find teams slipping back into old methods as they encounter enterprise ...

    Java.for.Bioinformatics.and.Biomedical.Applications.(2007).part1.rar

    it takes a deep dive into demonstrating how to build highly functional graphical user interfaces for common and widely used bioinformatics tools that most researchers are familiar with and find ...

    [3planesoft屏幕保护程序合集].Premium.3D.Screensavers.iso

    Find yourself in a mysterious dwelling gnomes! Admire the impressive underground hall with antique fireplace, where the light is refracted in the columns and arches made of rock crystal, and at the ...

    swing文件拖拽

    // Ask the cell renderer to paint itself into the BufferedImage g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0.5f)); // Make the image ghostlike lbl.paint(g2); g2.dispose(); /...

    Java邮件开发Fundamentals of the JavaMail API

    further than the JavaMail API, which offers a protocol-independent model for working with IMAP, POP, SMTP, MIME, and all those other Internet-related messaging protocols. With the help of the ...

    微软内部资料-SQL性能优化3

    Consistency and isolation are the most important in describing SQL Server’s locking model. It is up to the application to define what consistency means, and isolation in some form is needed to ...

Global site tag (gtag.js) - Google Analytics