【发布时间】:2016-07-14 21:51:00
【问题描述】:
我敢肯定,这应该很简单,但我是一个超级新手。基本上,有一个带有电话号码表单字段的网站,当用户点击提交时,它将向电话号码发送一条消息。 (使用 Twilio)
javascript:
$("#phoneNumberButton").click(function(){
console.log( $("#styled").val());
var phoneNumberString = $("#styled").val();
phoneNumberString = phoneNumberString.replace(/\D/g,'');
if ( phoneNumberString.length != 10 ) {
$('#styled').tooltipster('show');
} else {
$('#phoneNumberButton').text('Link sent!');
$.post( '_/ruby/TwilioSend.rb', {'phoneNumber': phoneNumberString} );
红宝石('_/ruby/TwilioSend.rb):
require 'twilio-ruby'
account_sid = "xxxx"
auth_token = "yyyy"
@client = Twilio::REST::Client.new account_sid, auth_token
message = @client.account.messages.create(:body => "Hello from Ruby",
:to => params[:phoneNumber], # Replace with your phone number
:from => "+15555555555") # Replace with your Twilio number
puts message.sid
当我在终端中执行 ruby 文件时,它可以使用静态 ':to' 变量。但我不能让他们一起工作。你能告诉我我做错了什么吗?我敢肯定有很多东西......仅供参考,这就是我们使用的所有红宝石。没有其他红宝石文件。 php 给我们带来了问题。
【问题讨论】:
标签: javascript ruby ajax http-post twilio