我一直在麻煩一會兒讓這個put方法工作。Ruby中'更新'的NoMethodError
我收到以下錯誤消息的「成功」行!
NoMethodError - 未定義的方法'更新」對於零:NilClass
請參閱下面的代碼:
#edit download
put '/view1/downloadedit' do
data = JSON.parse(request.body.read)
edit_id = data[0]["downloadID"]
@download_edit = Download.get(:download_id => edit_id)
puts @download_edit
success = @download_edit.update![0][data]
if success
status 201
puts 'edit saved okay'
else
status 201
puts 'edit failed to SAVE'
end
end
Download.rb
#class download
class Download
include DataMapper::Resource
property :downloadID, Serial, key: true
property :PageID, String
property :title, String
property :dlLink, String
property :imgSrc, String
property :caption, String
property :dlLive, Integer
property :createdAt, DateTime
property :user_id, Integer
end
你用'puts @ download_edit'得到了什麼?我認爲你有幾個問題,但其中一個是'@ download_edit = Download.get(:download_id => edit_id)' – RustyToms
現在只是一個空行,這是奇怪的:S –
是的它是作爲零出現:/ –