Twilio sms表单在本地工作,但没有推送到heroku - Ruby

时间:2016-02-11 04:24:41

标签: ruby-on-rails ruby heroku devise twilio

新手来到红宝石轨道上 - 没有能够找出这个问题。它可能非常简单。

我使用Twilio的api / sms功能构建了一个RoR站点,因此我可以send text messages给我的用户(使用activeadmin和devise)。一切似乎都适用于当地,但当我向Heroku推进时,我遇到了一个问题。

在我的仪表板上的activeadmin内部,我添加了表单字段来发送短信 (http://i.stack.imgur.com/TXLrq.png

我有一些观点>管理员>仪表板> _send_a_message.html.erb和_send_message_all.html.erb我有

<%= form_tag('/send_sms', method: 'POST') do %>
<input type="text" placeholder="enter number" name="number">
<input type="text" placeholder="enter message here" name="message">
<button type="submit">Submit</button>
<% end %>

<%= form_tag('/send_sms', method: 'POST') do %>
<input type="text" placeholder="enter number" name="number">
<input type="text" placeholder="enter message here" name="message">
<button type="submit">Submit</button>
<% end %>

我将这些呈现在activeadmin仪表板中,然后再放入我的TwilioController&#39;我有这两个:

def send_sms
 message = params[:message]
 number = params[:number]
 account_sid = 'my sid'
 auth_token = 'my token'

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

 @message = @client.account.messages.create ({:to => "+1"+"#{number}",
                                              :from => "+my number",
                                              :body => "#{message}"})
 redirect_to '/admin/dashboard', :flash => { :success => "Your message sent!" }

 rescue Twilio::REST::RequestError => e
 puts e.message
end

def send_sms_all
 user_phones = User.where(:subscribed => true).pluck(:phone)
 message = params[:message]
 account_sid = 'my sid'
 auth_token = 'my token'

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

 user_phones.each do |number|
  @client.account.messages.create ({:to => "+1"+"#{number}",
                                    :from => "+my number",
                                    :body => "#{message}"})
 end 

 redirect_to '/admin/dashboard', :flash => { :success => "Your message sent!" }

 rescue Twilio::REST::RequestError => e
 puts e.message
end

我的路线是

post '/send_sms' => 'twilio#send_sms'
post '/send_sms_all' => 'twilio#send_sms_all'

这一切似乎在本地工作正常 - 可以发送消息。当我向上推送到heroku并提交任何一个表格时,它会指示我/ send_sms页面,它给了我&#34;我们很抱歉,但出了点问题。&#34;页面并没有发送短信。

我的heroku日志似乎没有任何错误&#39;在他们中指出。这个问题是否与get vs post有关?我已经尝试过heroku run rake和db:migrate以确保所有设置完成并且看起来很好。

有任何帮助吗?如果您需要查看别的内容,请告诉我。

更新:我最初调用了我的secrets.yml文件,其中存储了令牌和SID,而Heroku并不喜欢这样。在我的production.rb文件中,我有这个:config.middleware.use Rack :: TwilioWebhookAuthentication,Rails.application.secrets.twilio_auth_token,&#39; / send_sms&#39;,&#39; / send_sms_all&#39;

所以我将它们移动到一个.env文件中,并将它们改为:config.middleware.use Rack :: TwilioWebhookAuthentication,ENV [&#39; TWILIO_AUTH_TOKEN&#39;],&#39; / send_sms&#39; ,&#39; / send_sms_all&#39;但这给了我一个新问题&#34; Twilio请求验证失败。&#34;我修改了两个&#39; // send_sms&#39;,&#39; // send_sms_all&#39;。

希望这一切在未来帮助别人!感谢所有帮助过以下的人!

1 个答案:

答案 0 :(得分:0)

  

更新:我最初是在我的secrets.yml文件中调用我的令牌   和SID存储,Heroku不喜欢这样。在我的production.rb   文件我有这个:config.middleware.use Rack::TwilioWebhookAuthentication, Rails.application.secrets.twilio_auth_token, '/send_sms', '/send_sms_all'

     

所以我将它们移动到.env文件中并像这样调用它们   相反:config.middleware.use Rack::TwilioWebhookAuthentication, ENV['TWILIO_AUTH_TOKEN'], '/send_sms', '/send_sms_all'但是给了   我是一个新的“Twilio请求验证失败”。我修好了   制作两个'//send_sms', '//send_sms_all'