this is my ajax call section in js file :
$("#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);
}
});
});
This is my controller Action :
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
In in create actions (else part), I need to pass json response regarding( invalid user/ invalid user credentials) to my ajax call, which I can alert user on the View Page.