Closed samstickland closed 7 years ago
OK, I found the problem.. That was a red herring above.
The problem is that for a collection the options all end up in model
, but in cells-rails options is initialised in the rails helper:
options[:context] ||= {}
options[:context][:controller] = self
Then in cells there's this bit of code in Cells (lib/cell/view_model.rb) where it merges the options for a collection
def call(model=nil, options={}, &block)
if model.is_a?(Hash) and array = model[:collection]
return Collection.new(array, model.merge(options), self)
end
build(model, options)
end
The problem is that both model
and options
contain a context
key so one of them gets overwritten, rather than merged.
A possible fix would be this:
def call(model=nil, options={}, &block)
if model.is_a?(Hash) and array = model[:collection]
merged_context = (model[:context] || {}).merge(options[:context])
merged_options = model.merge(options)
merged_options[:context] = merged_context
return Collection.new(array, merged_options, self)
end
build(model, options)
end
https://github.com/samstickland/cells/commit/1ff3eac397ec87344cb1bdcafb1365c21dab1fa6
Sorry, I won't have time to write a test for this until next week.
This is tested and fixed.
@apotonick : Hi Nick, which release can I find this fix in?
Latest Cells!
Hi,
context only seems to get passed to the first loop when rendering a cell with a collection.
I call the cell like this:
In the first collection entry context is set correctly:
But in the second invocation it's current_user is gone: