2016-11-15 39 views
-2

应用程序使用REST API发送消息,但是按照原样,“to”号码被硬编码到应用程序中。我希望这个号码是用户输入的值。在Ruby中接收电话号码输入

HTML: 

<!DOCTYPE html> 
<head> 
    <title>Joe's Web App</title> 
    <link rel="stylesheet" type="text/css" href="index.css" media="screen"/> 
</head> 
<body> 
    <div class="content"> 
    <div class="words"> 
     <h1>My Name</h1> 
     <p> 
     Insert your number below to recieve a text! 
     </p> 
    </div> 
    <input type="tel" placeholder="Phone Number" name="number"> 
    <input type="submit"> 
    </div> 
</body> 

红宝石:

require 'rubygems' 
require 'twilio-ruby' 

account_sid = 'AC26b29f734e8145f6df3497eb6ca50205' 
auth_token = 'my auth token' 

@client = Twilio::REST::Client.new account_sid, auth_token 

@client.account.messages.create({ 
    :from => 'Twilio Number', 
    :to => 'phone number', 
    :body => 'Hey this is Joe!', 
}) 
+0

我认为,如果你建立与机架这将是简单的。更多细节.. https://codenoble.com/blog/ruby-web-applications-without-rails/ –

+0

所以你的意思是,你想在sinatra中实现这个或者什么? – marmeladze

+0

欢迎来到Stack Overflow。这并不完全清楚你想要什么。 –

回答

0

与后航线包裹它,如果你想使用西纳特拉。

原始代码应该是,

post '/send_message' do 
    @client = Twilio::REST::Client.new account_sid, auth_token 
    @client.account.messages.create({ 
    from: 'Twilio Number', 
    to: params[:number], 
    body: 'Hey this is Joe!', 
    }) 

end