ga-wdi-boston / capstone-project

Other
3 stars 29 forks source link

trouble with patch showing up on click #858

Closed jillrizley closed 6 years ago

jillrizley commented 6 years ago

Having issues with my PATCH. I want to update the album so it updates immediately. I can sign out and in and it updates and I am getting a PATCH. however, after trying what feels like everything, I can’t seem to get it to update after submit. I think I’m probably just missing something silly. I know it says album of undefined, but I'm not sure what I am supposed to add to the UI

I get this error in the web dev console

jquery.js:3860 jQuery.Deferred exception: Cannot read property 'album' of undefined TypeError: Cannot read property 'album' of undefined  at HTMLFormElement.onUpdateSuccess 

API

const update = function (data, id) {
  return $.ajax({
    method: 'PATCH',
    url: config.apiOrigin + '/albums/' + id,
    headers: {
      Authorization: 'Token token=' + store.user.token
    },
    data
  })
}

events

const updateAlbum = function (e) {
  e.preventDefault()
  const data = getFormFields(e.target)
  api.update(data, data.album.id)
    .then(ui.onUpdateSuccess.bind(this))
}

UI (albumTemplate is my handlebars)

const onUpdateSuccess = function (data) {
  $('#editAlbumModal').modal('hide')
  $('#content').append(albumTemplate(data.album))
}
payne-chris-r commented 6 years ago

Why are you binding this?

payne-chris-r commented 6 years ago

What is data in onUpdateSuccess?

jillrizley commented 6 years ago

Good point, the binding isn't needed. The data is the updated information I entered. I think I'm having trouble with where the information is going as well. Not sure if content is the right place for it.

scottyscripts commented 6 years ago

Can you post what data actually looks like when you log it in your onUpdateSuccess function?

jillrizley commented 6 years ago

ohhhh crap. undefined. not sure where I'm making the error

jquery.js:3860 jQuery.Deferred exception: Cannot read property 'album' of undefined TypeError: Cannot read property 'album' of undefined
    at Object.onUpdateSuccess (http://localhost:7165/public/application.js:1008:42)
    at mightThrow (http://localhost:7165/public/vendor.js:13220:29)
    at process (http://localhost:7165/public/vendor.js:13288:12) undefined
scottyscripts commented 6 years ago

Does your update controller action in your API currently return any data?

MicFin commented 6 years ago

Status?

jillrizley commented 6 years ago

ah sorry! forgot to write back, I worked it out!!