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