Closed ghost closed 9 years ago
We don't support #content_for
(so far) - it completely defeats the purpose of encapsulating your view part. :laughing:
I won't implement a new version of cells-capture
as I think content_for
is a horrible idea and can easily be achieved with clean encapsulation:
comment_cell = cell(:comment, @comment)
html = comment_cell.() # calls #show
more_html = comment_cell.(:more) # calls #more
Would that work for you?
Sure! It does the trick, even though it goes the other way round. I know is more correct thinking in the concept of encapsulation, but what I wanted to avoid was having a lot of references to the cell in my main app. Anyway, as I told you, it works and its a good solution.
Thanks for your help and quick response!
Implementing a cells-content-for
gem/module would actually be quite simple: You override the #cell
helper and pass in the global AV instance as an option, somehow along this.
cell(:comment, @comment, action_view: self)
In the cell, you'd define a delegation to action_view
.
class CommentCell < Cell::ViewModel
delegates :action_view, :content_for
That should do the trick.
Hi there,
I know that this is a very discussed topic, but I'm still having problems trying to use "content_for" inside of my cells views. I tried to use the "cells-capture" gem, but it seems to be outdated and throws an exception in the rails service initialization. I also tried to adapt its code and make it work with Cells 4 with no luck.
I saw another issue with a workaround to do this (https://github.com/apotonick/cells/issues/25), but is older than the capture gem, so I suppose and still have hope that you have another solution. :D
So... are there any way to use "content_for" in Cells 4? I'm getting a "NoMethodError" exception ("undefined method `append' for nil:NilClass").
Thanks in advance!