Trying update post with ajax.
posts_controller.rb
def update
if @post.update_attributes(post_params)
flash[:notice] = 'Post updated!'
redirect_to @post
else
flash[:alert] = 'Something wrong'
render :edit
end
end
application.js
$('.simple_form.edit_post').submit('submit', function (e) {
e.preventDefault();
form = $(this).serialize();
$.ajax({
type: 'POST',
action: $(this).attr('action'),
data: form,
dataType: 'JSON'
}).done(function (data) {
alert(data.notice);
}).fail(function (data) {
alert(data.alert);
});
});
When i try update i get error in Chrome console Page not found and alert output undefined