我有一个控制器问题,旨在检测任务/待办事项并将其传递给视图。
在我的应用程序布局中,我有一个保留空间来呈现这些任务
<%= yield(:tasks) if content_for?(:tasks) %>
这是我在 ApplicationController 中包含的模块。它似乎无法正常工作并且content_for?(:tasks)
返回错误(byebug 说)
module TaskControl
extend ActiveSupport::Concern
included do
before_action :check_tasks
def check_tasks
if user_signed_in? and current_user.tasks.todos.any?
# TODO : better task strategy afterwards
view_context.provide(:tasks,
view_context.cell(:tasks, current_user.tasks.todos.first)
)
end
view_context.content_for?(:tasks) # => false :'(
end
end
end
请注意,我确实检查过 byebug,
view_context.cell(:tasks, current_user.tasks.todos.first).blank? # => false, so there is something to render