Ruby on rails 使用nexmo gem从rails中的输入字段发送SMS
我正在尝试使用Nexmo gem向输入字段中输入的号码发送短信 这就是我目前所拥有的,但它似乎不起作用 pages/test.html.erbRuby on rails 使用nexmo gem从rails中的输入字段发送SMS,ruby-on-rails,forms,nexmo,Ruby On Rails,Forms,Nexmo,我正在尝试使用Nexmo gem向输入字段中输入的号码发送短信 这就是我目前所拥有的,但它似乎不起作用 pages/test.html.erb <%= form_tag "/pages/send_sms" do -%> <%= text_field_tag "number" %> <%= submit_tag "Send" %> <% end -%> pages\u controller.rb def send_sms @numb
<%= form_tag "/pages/send_sms" do -%>
<%= text_field_tag "number" %>
<%= submit_tag "Send" %>
<% end -%>
pages\u controller.rb
def send_sms
@number = params[:number]
nexmo = Nexmo::Client.new(
key: ENV['NEXMO_API_KEY'],
secret: ENV['NEXMO_API_SECRET']
)
notification = "Download the app through this link"
response = nexmo.send_message(
from: "GLAM360",
to: params['number'],
text: notification
)
if response['messages'].first['status'] == '0'
redirect_to root_path
end
end
这是我在终点站看到的
Started POST "/pages/send_sms" for 127.0.0.1 at 2017-10-08 00:35:45 +0400
Processing by PagesController#send_sms as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"zPj5PcZrD+uNYxvvfDio8B5uNWitg0vMw+3Vm8KbvQumbNWzsgN4sBJDKsi2srx0rSatiOISegWHQFE860
JxcA==", "number"=>"+971585959698", "commit"=>"Send"}
No template found for PagesController#send_sms, rendering head :no_content
Completed 204 No Content in 803ms
在此将非常感谢您的任何帮助错误本身会告诉您该怎么做。你几乎没有选择
if响应['messages'].first['status']=='0'
将\重定向到根\路径
其他的
重定向到测试路径
结束
错误本身告诉您该怎么做。你几乎没有选择
if响应['messages'].first['status']=='0'
将\重定向到根\路径
其他的
重定向到测试路径
结束
看起来响应状态不是0,因此它正在查找send_sms视图模板。我假设您没有发送短信的视图,因此显示了“
未找到…”
的模板。看起来响应状态不是0,因此它正在查找发送短信视图模板。我假设您没有发送短信的视图,因此显示了“未找到…”
的模板。嘿,Saurav,感谢您的回复。你能和我分享一下代码吗?我已经添加了else语句,但是短信似乎仍然没有通过。嘿,我终于成功了。谢谢你给我指出了正确的方向。嘿,索拉夫,谢谢你的回应。你能和我分享一下代码吗?我已经添加了else语句,但是短信似乎仍然没有通过。嘿,我终于成功了。谢谢你给我指明了正确的方向。
Started POST "/pages/send_sms" for 127.0.0.1 at 2017-10-08 00:35:45 +0400
Processing by PagesController#send_sms as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"zPj5PcZrD+uNYxvvfDio8B5uNWitg0vMw+3Vm8KbvQumbNWzsgN4sBJDKsi2srx0rSatiOISegWHQFE860
JxcA==", "number"=>"+971585959698", "commit"=>"Send"}
No template found for PagesController#send_sms, rendering head :no_content
Completed 204 No Content in 803ms