You’ve set up @variable as an array of hashes and are trying to access
it in your partial as a simple hash. You need to make your mind up
whether you want an array, a hash, or something more complex.
Simon wrote:
def my_controller @variable = [{‘myfield’=>‘grey’},{‘myfield’=>‘blue’}]
end
My understanding of the render :partial syntax is that when you use
the :collection part, you pass an array to that argument and each
element in that array is passed to the parial called (my_partial) as a
local variable partial_name (my_partial)
So at this point, if you have an array of simple hashes then each time
my_partial runs it should run with a simple hash called my_partial
If my understanding is correct, then I think the code should run.
Is there definitely data in the @variable before you call the partial?
Could you post your actual code?
Cheers
Yeah thought of that, the @variable has the array of hashes in it at the
view stage. The code above is exactly what I have test(with no missing
quote).
thanks Daniel,
after display the local variables, it appears as though the keys of the
hash
are converted into variables directly. In this example, the local
variable ‘myfield’ becomes created in the partial as opposed to
accessing it through my_partial[‘myfield’] as i would have expected.
The my_partial local variable then becomes a nil object.
I ran into this problem, also. with an array of hashes being passed. It
didn’t even seem to convert each has item into a local variable
correctly (some didn’t exist, some were nil). Snippet below