I have a controller concern which aims at detecting and passing tasks/todos to the view.
In my application layout I have a reserved space to render those tasks
<%= yield(:tasks) if content_for?(:tasks) %>
Here is the module that I include in ApplicationController. It doesn't seem to work properly and the content_for?(:tasks)
returns false (byebug says)
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
Note that I did check with byebug,
view_context.cell(:tasks, current_user.tasks.todos.first).blank? # => false, so there is something to render