0
救我試圖挽救一些數據弗羅姆模型對象,但沒有任何反應:( 我做些什麼不對?紅寶石DataMapper的從模型
class Gallery
include DataMapper::Resource
property :id, Serial
property :title, String
property :user, String
property :album, String
property :place, String
property :fotki, Text
property :date, Date
property :created_at, DateTime
default_scope(:default).update(:order => [:created_at.desc])
def get_images
if @fotki.nil? then
fotki = Fotki.get(@user, @album)
self.update(:fotki => fotki.to_json)
puts 'Request'
fotki
else
puts 'Use Cache'
JSON.parse(@fotki)
end
end
end
你究竟想要做什麼?閱讀你的代碼並不清楚。我不相信'update'接受這樣的':order',因爲它不是一個選擇查詢,而是一個更新。除此之外,你不應該試圖直接從類內部寫入數據。添加一個方法並顯式調用它。只要該類碰巧被加載到內存中,該代碼就會運行,這是不好的。 – d11wtq
我使用外部服務來存儲照片。並使用它的API來獲取指定的照片網址:用戶和:相冊編號。然後我得到它我想將數據緩存在數據庫中,而不是將來新的請求。我像那個庫調用= Gallery.get(params [:id]); photos = gallery.get_images – Leonid
'gallery.errors'包含什麼?當我發表我的第一條評論時,我的部分出現了一些混淆,關於'default_scope'調用的用途。這不是一個非常清晰的界面,但這就是DM。我現在學到了一些東西! – d11wtq