In my RoR application, i have a rjs file which is populating a field with id "submission_references" found in my main form.
RJS code:
page[:submission_references].value = @references.each do |reference|
reference.NAME
end
The problem is that instead of displaying the retrieved database value, the following is being displayed in the 'submission_references' field:
[object Object],[object Object]
However if i put something like @references[0].NAME, the first retrieved record’s name is displayed in the field.
Please can someone shed some light on this for me.
Many many thanks for your precious help
Try:
A little explanation: in your code you have assigned to the
valuea result ofeachloop, which returns original array of objects (not the evaluated inside block). That is why you get that[object Object],[object Object]string. On the other sidemapiterates over a collection and it evaluates block for each object in collection. Evaluated values are then returned in array instead of orginal objects. SinceNAMEis a string, you can usejoin(", ")to join each element of an array into one string concacted with “, ” string.