The scope_out plugin will generate several helpful find methods for you automatically! It's the best way to move the find conditions into your model. Watch this episode for details.
script/plugin install http://scope-out-rails.googlecode.com/svn/trunk/# models/task.rb
scope_out :incomplete, :conditions => ['complete=?', false], :order => 'name'
# tasks_controller.rb
@tasks = Task.find_incomplete(:all)
# models/project.rb
has_many :tasks, :extend => Task::AssociationMethods
# projects_controller.rb
def show
@project = Project.find(params[:id])
@tasks = @project.tasks.find_incomplete(:all)
end
Scope-Out 插件能自动生成多种查找方法,帮助将查找条件迁移到模型中。该插件简化了Rails应用中任务与项目的关联查询过程,通过定义特定的范围查询,如查找未完成的任务等。
3088

被折叠的 条评论
为什么被折叠?



