#76 scope_out

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

你可能感兴趣的:(SVN,Rails)