1

Rails 3.2.8,ruby 1.9.3p0(2011-10-30 修订版 33570)[x86_64-linux]

当我在另一个带有instance方法的清扫器中使用清扫器时,清扫器功能(如 after_update)被执行(我做了一个日志并被执行)但在我的项目中没有过期。(或任务)

我的代码是下一个:

class WorkSweeper < ActionController::Caching::Sweeper
  # ...
  def after_update(work)
    expire work, "/works/index"
    expire work, "/tasks/#{work.task_id}/works/index"

    expire work, "/works/#{work.id}/show"

    TaskSweeper.instance.after_update work.task
  end
  # ...
end

class TaskSweeper < ActionController::Caching::Sweeper
  # ...
  def after_update(task)
    expire task, "/tasks/index"
    expire task, "/milestones/#{task.target_id}/tasks/index"
    expire task, "/tasks/#{task.target_id}/tasks/index"
    expire task, "/projects/#{task.target_id}/tasks/index"

    expire task, "/tasks/#{task.id}/show"

    MilestoneSweeper.instance.after_update task.target if task.target.class == Milestone
  end
  # ...
end

class MilestoneSweeper < ActionController::Caching::Sweeper
  # ...
  def after_update(milestone)
    expire milestone, "/milestones/index"
    expire milestone, "/projects/#{milestone.project_id}/milestones/index"

    expire milestone, "/milestones/#{milestone.id}/show"

    ProjectSweeper.instance.after_update milestone.project
  end
  # ...
end

class ProjectSweeper < ActionController::Caching::Sweeper
  # ...
  def after_update(project)
    expire project, "/projects/index"
    expire project, "/companies/#{project.company_id}/projects/index"

    expire project, "/projects/#{project.id}/show"
  end
  # ...
end

注:expire是下一个函数

def scope(project)
  project.creator.try(:creator_id) || project.creator_id
end

def expire(model, url)
  expire_fragment("#{scope model}#{url}")
end

我需要在每个清扫器中手动执行每个过期,例如:

class WorkSweeper < ActionController::Caching::Sweeper
  # ...
  def after_update(work)
    expire work, "/works/index"
    expire work, "/tasks/#{work.task_id}/works/index"

    expire work, "/works/#{work.id}/show"

    expire project, "/projects/index"
    expire project, "/companies/#{project.company_id}/projects/index"

    expire project, "/projects/#{project.id}/show"
  end
  # ...
end

在这种情况下,工作,但它不是最好的,我有很多模型和很多扫地机。

怎么了?还有另一种方法可以做到这一点吗?

谢谢。

解决了

在这里回答https://github.com/rails/rails/issues/8096

4

0 回答 0