2016-11-15 4 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

ようこそスタックオーバーフロー。あなたが望むものは完全にはっきりしていません。 –

答えて

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 
関連する問題