I've been having trouble for a while getting this put method to work.
I'm getting the following error message on the 'success' line:
NoMethodError - undefined method `update!' for nil:NilClass
Please see the code below:
#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
You need to fix how you are retrieving your model and how you are updating it, so change your code to this: