2

I'm creating an app in Rails that uses ActionCable/Websockets and I'm using coffeescript to update a users browser with data received from the current channel in ActionCable. When I run this code I get the error "Uncaught TypeError: data.user.name is not a function", however when I swap data.user.id and data.user.name the error is then for data.user.id. I think my syntax is wrong but I can't find any answers. Any help would be appreciated. Thanks

received: (data) ->
  $('#players-table').show()
  $('#players-table-body').append '<tr>' + 
    '<td>' + data.user.id + '</td>' + 
    '<td>' + data.user.name +'</td>'

1 Answer 1

2

It'll sound strange, but you need an space after the last +:

received: (data) ->
  $('#players-table').show()
  $('#players-table-body').append '<tr>' + 
    '<td>' + data.user.id + '</td>' +
    '<td>' + data.user.name + '</td>'

Without it, it'd make the data.user.name to open parenthesis and to put inside the +'</td>', like:

return $('#players-table-body').append('<tr>' + '<td>' + data.user.id + '</td>' + '<td>' + data.user.name(+'</td>'));
Sign up to request clarification or add additional context in comments.

2 Comments

Great it worked, I've just edited the title if somebody else has the same problem.
yeah thanks, I did mark it but said I had to wait 10 mins

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.