Javascript 使用AJAX(rails)跨域登录用户
我有一个问题,我有一个web应用程序,它有一个登录页和信息的www,它有一个“app.application.io”。我允许用户在www.页面上创建帐户,然后他们需要在同一页面上输入信用卡信息。问题是我无法在不重定向到“app.”域的情况下登录它们 这是我的密码:Javascript 使用AJAX(rails)跨域登录用户,javascript,ruby-on-rails,ajax,Javascript,Ruby On Rails,Ajax,我有一个问题,我有一个web应用程序,它有一个登录页和信息的www,它有一个“app.application.io”。我允许用户在www.页面上创建帐户,然后他们需要在同一页面上输入信用卡信息。问题是我无法在不重定向到“app.”域的情况下登录它们 这是我的密码: #Create account def create dont_redirect = params[:dont_redirect] organization_name = params[:organization_name]
#Create account
def create
dont_redirect = params[:dont_redirect]
organization_name = params[:organization_name]
organization_prefix = organization_name.gsub(/\s+/, "").downcase
#Check if there's an organization with this source email already
existing_organizations = Organization.active
.select("1")
.where("source_email like '%#{organization_prefix}%'")
#If we do have an organization then append a number to the end
organization_prefix = organization_prefix + existing_organizations.count.to_s if existing_organizations && existing_organizations.count > 0
source_email = organization_prefix + '@contactflowmail.com'
organization = Organization.create!(name: organization_name, source_email: source_email, billing_plan_id: 1,
subscription_ends_at: Time.now + 14.days)
user = User.new(user_params)
user.organization = organization
user.role = 'owner'
user.source = params[:source]
#Creates the account for the user and signs them in if it is successful
if user.save
sign_in(user)
#Add contact to Contact Flow Contact Flow account
ContactFlow.addContact(user.first_name, user.last_name, user.email, 'cf-trial')
if dont_redirect
render json: {success: true, organization_id: user.organization_id}
else
redirect_to ENV['APP_ROOT_PATH'] + "/onboarding"
end
else
render json: {success: false, message: user.errors.full_messages.join("<br />")}
end
end
#创建帐户
def创建
dont\u redirect=params[:dont\u redirect]
组织名称=参数[:组织名称]
organization_prefix=organization_name.gsub(/\s+/,“”)。downcase
#检查是否有组织已使用此源电子邮件
现有组织=Organization.active
.选择(“1”)
.where(“源电子邮件,如“%{organization\u prefix}%”)
#如果我们有一个组织,那么在末尾加上一个数字
organization_prefix=organization_prefix+existing_organizations.count.to_s(如果现有_organizations&&existing_organizations.count>0)
source_email=organization_prefix+'@contactflowmail.com'
组织=组织。创建!(名称:组织名称,来源电子邮件:来源电子邮件,账单计划id:1,
订阅结束时间:Time.now+14天)
user=user.new(用户参数)
user.organization=组织
user.role='owner'
user.source=params[:source]
#为用户创建帐户,如果成功,则将其登录
如果user.save
登录(用户)
#将联系人添加到联系人流联系人流帐户
ContactFlow.addContact(user.first\u name、user.last\u name、user.email、“cf试用版”)
如果你不重定向
呈现json:{success:true,organization\u id:user.organization\u id}
其他的
重定向到ENV['APP\u ROOT\u PATH']+“/onboarding”
结束
其他的
呈现json:{success:false,message:user.errors.full_messages.join(“
”)}
结束
结束
如果你有任何问题,请提问