Tôi dưới:
Rails 3.0.9
lập mưu 1.4.7
jquery-ujsRails 3 lập mưu Ajax đăng nhập Сatching Thông báo lỗi
đã làm gì gì ...
1) Tôi có? thiết lập biểu mẫu đăng nhập với data-remote = "true".
2) Tôi đã thiết lập các trình xử lý jquery đăng nhập:
('form#user-reg-form')
.bind("ajax:beforeSend", function(evt, xhr, settings){
})
.bind("ajax:success", function(evt, data, status, xhr){
$('#comments').append(xhr.responseText);
})
.bind('ajax:complete', function(evt, xhr, status){
})
.bind("ajax:error", function(evt, xhr, status, error){
try {
errors = $.parseJSON(xhr.responseText);
} catch(err) {
errors = {message: "Please reload the page and try again"};
}
errorText = "There were errors with the submission: \n<ul>";
for (error in errors) {
errorText += "<li>" + error + ': ' + errors[error] + "</li> ";
}
errorText += "</ul>";
// Insert error list into form
$form.find('div.validation-error').html(errorText);
});
3) Tôi đã định nghĩa lại bộ điều khiển phiên như thế này:
def create
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")
sign_in(resource_name, resource)
return render :json => { :success => true, :content => current_user.email }
end
def failure
return render:json => {:success => false, :errors => ["Login failed."]}
end
4) Tôi đã thiết của tôi route.rb file:
devise_for :users, :controllers => {:sessions => "sessions"}
Mọi thứ hoạt động ... nhưng khi tôi gửi sai email hoặc mật khẩu, tôi không nhận được tin nhắn từ email hoặc mật khẩu người dùng "có thể từ Devise)". Nhưng tôi muốn nắm bắt thông báo này và đặt nó vào đối tượng json giống như thế này trả về kết xuất: json => {: success => false,: errors => //// email hoặc mật khẩu sai ////}
Khả năng là: : gọi lại không hoạt động. Có vẻ như Warden.authenticate! không thấy phương pháp lỗi của tôi
Cảm ơn trước.