看板 Ruby 關於我們 聯絡資訊
: 推 kewang:這樣子寫我知道可以,可是我想讓user可以顯示全部的欄位, 09/08 15 : → kewang:因為我要to_json,照文中的寫法會無法顯示laptop.*,只會出 09/08 16 : → kewang:現user.name, user.laptop_id而已 09/08 16 提供一個笨方法 u = User.first u.attributes.merge('laptop' => u.laptop.attributes).to_json or l = Laptop.first l.attributes.merge('users' => l.users.map(&:attributes)).to_json 重點在於,反正 attributes 會給你所有的資料,就自己組合吧 -- Hear me exalted spirits. Hear me, be you gods or devils, ye who hold dominion here: I am a wizard without a home. I am a wonderer seeking refuge. Sacrifice -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 1.171.118.81
kewang:這個酷耶!主要還是我的Ruby(Rails)語法不熟,要多學 囧rz 09/08 20:46