I am experimenting with Rails and the AJAX helper - remote: true
. I have a view with a link:
<%= link_to 'My Profile', edit_user_path(current_user), class: 'user-profile', remote: true %>
This fires an AJAX request to a controller:
def edit
@user = User.find(params[:id])
respond_to do |format|
format.html
format.js { render plain: "Test" }
end
end
Which returns "Test" to my js ajax listener:
$(document).ready(function() {
$('.user-profile').on('ajax:success', function(response) {
console.log(response)
let data = response.detail[0]
$('.profile-content').append(data)
});
$('.user-profile').on('ajax:error', function(event) { console.log(response) })
})
Everything works as expected. "Test" is appended ( I have also appended views and JSON objects). However, whenever I get a response back, I get a JS error in my console:
If I render an HTML view then I get:
What could be causing this? Its driving me mad because everything works as expected but I get an error.