I have an array in my ruby like the following:
[#<Order::List code: 1511, Reference: "FRIA004", valuation: nil, full_Address: "1, abc road, xyz", reason_available: "Y", list: "1 : Meter cupboard generic throughout - Very low">,
#<Order::List code: 1512, Reference: "FRIA005", valuation: nil, full_Address: "2, abc road, xyz", reason_available: "Y", list: "2 : Meter cupboard generic throughout - Very high, 3 : Meter cupboard generic throughout - Very low">,
#<Order::List code: 1513, Reference: "FRIA006", valuation: nil, full_Address: "3, abc road, xyz", reason_available: "Y", list: "15 : Meter cupboard generic throughout - Low">,
#<Order::List code: 1514, Reference: "FRIA007", valuation: nil, full_Address: "6, abc road, xyz", reason_available: "Y", list: "16 : Meter cupboard generic throughout - High">]
Model:
class Order::List < ActiveRecord::Base
self.primary_key = :Code
def self.display_details(codes)
codes.each { |x|
details = Order::List.where(Code: x).first
reference = details.Reference
address = details.full_Address
list = details.list
display_details = reference + "\n" + address + "\n" + list
return display_details
end
end
View:
So I can display the detail list into the textarea like the following:
<%= f.text_area :detail_list, rows: 8, value: (Order::List.display_details(codes)) %>
Output:
FRIA004
1, abc road, xyz
2 : Meter cupboard generic throughout - Very high, 3 : Meter cupboard generic throughout - Very low
Questions:
1) It has been stopped after return the first code. I am using each and want to display each of the code into the text_area
2) How can I display the list(list is the column here) into the new line after the comma?
So my expected output is
FRIA004
1, abc road, xyz
1 : Meter cupboard generic throughout - Very low
FRIA005
2, abc road, xyz
2 : Meter cupboard generic throughout - Very high
3 : Meter cupboard generic throughout - Very low