0
比方說,我已經獲得了一些由ActiveRecord find_by_sql調用返回的數據。對於一個查詢返回的數據是這樣的:Ruby Rails Activerecord列遍歷來檢查空值
id UserId City State Zip Country Email Phone Age 1 fred Atlanta GA 300909 null [email protected] null 35 2 Sue New York NY 99801 null [email protected] null 38 3 Bill Dallas TX 87654 null [email protected] null 25
然後,我與這些價值觀其他數據集:
id UserId City State Zip Country Email Phone Age 4 fred null GA 300909 null null 555-1212 null 5 Sue null NY 99801 null null 555-1213 null 6 Bill null TX 87654 null null 888-2121 null
因爲我們有可選字段,我們不知道哪個數據將填充每種情況。我希望能夠在頁面上列出我有數據的所有字段,而不是顯示每個場景的空列。爲了這個例子,假定第一行中的任何值都將填充到該數據集中其餘行中。作爲一個方面說明,我還需要將這些值導出爲csv,並且不希望那裏也有空值。我已經搜索和搜索,並沒有弄清楚。我相信在Ruby中必須有一種方法可以做到這一點。任何幫助將不勝感激。
Hi @Mario。這對於城市,國家,電子郵件和年齡全都爲空的第二種情況如何起作用?實際上我有比這個例子更多的列。謝謝你的幫助。 –