Rails ModelSweeper.instance expires nothing
-
30-07-2021 - |
Question
Rails 3.2.8, ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
When I use a sweeper inside another sweeper with instance
method, the sweeper function (like after_update
) is executed (I did a log and is executed) but expires nothing in my project. (or Task)
My code is the next:
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
Note: expire
is the next function
def scope(project)
project.creator.try(:creator_id) || project.creator_id
end
def expire(model, url)
expire_fragment("#{scope model}#{url}")
end
I need to execute each expire manually in each sweeper, like:
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
In this case, works, but it is not the best, I have lots of model and lots of sweepers.
What is wrong? Is there another way to do the same?.
Thanks.
Solved
Answer here https://github.com/rails/rails/issues/8096
Pas de solution correcte
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow