Still trying to fix my ajax to work with the controller. Now I get this error message:
response SyntaxError: Unexpected token j , xhr[object Object] , STATUS parsererror
config.routes
resources :books do
member do
get '/last_chapter/', to: 'chapters#last_chapter', as: 'last_chapter', defaults: { format: 'json' }
end
resources :chapters
end
chapter controller
def last_chapter
@last_chapter = Chapter.order(created_at: :desc).limit(1)
respond_to do |format|
format.json
end
end
last_chapter.json
json.extract! @last_chapter, :id, :title, :characters, :created_at, :updated_at
script.js
$.ajax({
type: "GET",
url: '/books/103/last_chapter.json',
contentType: "application/json",
success: function(data) {
console.log('JAAAA ENDELIG FUNKER DET');
$("body").html(data);
},
error: function(xhr, status, response) {
console.log('response ' + response + ' , xhr' + xhr + ' , ' + 'STATUS ' + status)}
});
Feel like I have tried everything. Please let me know if you need anymore information! :)