【发布时间】:2014-03-03 14:16:16
【问题描述】:
这是我在 js 文件中的 ajax 调用部分:
$("#sign_submit").click(function(){
email_id = $("#user_email").val();
password = $("#user_password").val();
data = {email: email_id, password: password };
url = user/sign_in';
$.ajax({
url: url,
data: data,
cache: false,
type: "post",
success: function(data){
console.log(data);
}
});
});
这是我的控制器动作:
def create
@user = User.find_by_email(params['email'])
if @user.nil?
respond_to do |format|
format.json {render :json => {:response => 'User is invalid'} } #how to pass json response here.
end
end
if @user.check_valid_user?(params['password'])
set_dashboard_location
set_current_user(session[:customer_id])
render js: %(window.location.href='#{session["spree_user_return_to"]}')
else
#redirect_to '/' and return
#how to psas json response here.
end
end
在创建操作(其他部分)中,我需要将关于(无效用户/无效用户凭据)的 json 响应传递给我的 ajax 调用,我可以在查看页面上提醒用户。
【问题讨论】:
标签: jquery ruby-on-rails ajax