I'm trying to make an ajax call to communicate via 2 different apps
I am using localhost to host these apps, one in http://localhost:3000
and the other one in http://localhost:3001
in port 3000 I have devise setup with the basics
Here are the routes:
devise_for :users, controllers: { sessions: "users/sessions", registrations: "users/registrations" }
What I'm trying to do with the second app which is in port 3001, is to make an ajax post to sign in
here's the javascript:
$(function(){
$('#sign_in_user').on('click', function(){
var user = {
user: {
email: $('#sign_in_email').val(),
password: $('#sign_in_password').val()
}
};
$.ajax({
type: 'POST',
url: 'http://localhost:3000/users/sign_in',
dataType: 'json',
data: user,
success: function(newSignin){
console.log(newSignin);
},
error: function(){
alert('error');
}
});
});
});
but when it gets executed I get:
ActionController::InvalidAuthenticityToken at /users/sign_in
I've read a bit about the csrf meta tag, and beforeSend
on the ajax call, but haven't been able to solve the issue.
What am I doing wrong here?
ps. I am using the gem 'rack-cors'
to accept calls from other domains/apps.