私はたくさんのことを試してきましたが、この問題に頭を悩ませることはできません。まず最初に、ファンシーボックス内に部分的なフォームがあります。
これは:* _ form.html.erb *
<%= form_tag sessions_path , remote:true , id: "login_form" do %>
<div class="field">
<%= label_tag :email %>
<%= text_field_tag :email, params[:email] %>
</div>
<div class="field">
<%= label_tag :password %>
<%= password_field_tag :password %>
</div>
<div class="actions"><%= submit_tag "Inloggen" %></div>
<% end %>
application.jsのjQuery関数を使用して、このフォーム内にデータを投稿します
jQuery('#login_button').fancybox({
type: 'ajax'
})
jQuery('#login_form').submit(function() {
var data = jQuery(this).serialize();
$.getJSON('sessions/new.js?callback=?&variable=loginData', {
loginData: data
}, function(data) {
if(data == 0){
alert('Your account is not activated yet');
}
if(data == 1){
alert('Password incorrect');
}
// login correct
if(data == 2){
//$.fancybox.close();
window.parent.jQuery.fn.fancybox.close();
}
});
return false;
});
問題は、Iamがfancyboxにいるときにフィードバックが得られないことです。コンソールでXHRリクエストを確認すると、データが送信され、適切な応答が返されますが、ファンシーボックスが閉じず、アラートが表示されません。
最後になりましたが、私のセッションコントローラー
def create
@user = User.find_by_email(params[:email])
#if there is a user with that e-mail, is it activated?
if @user
if @user.user_level != '1'
@response = 1
end
end
#check the login information with has_secure_password, user has to be activated
if @user && @user.authenticate(params[:password]) && @user.user_level == '1'
session[:user_id] = @user.id
@response = 2
else
@response = 0
end
respond_to do |format|
format.json { render :json => @response }
end
応答が2に等しい場合、どうすればファンシーボックスを閉じることができますか?そして、ファンシーボックス内からの入力が正しくないことをユーザーに示すにはどうすればよいですか?