我正在整合SMS API在Rails應用程序中。雖然從用戶表取號我收到錯誤爲:MessageController中的類型錯誤#create_message沒有將字符串隱式轉換爲字符串
TypeError (no implicit conversion of nil into String):
app/models/message.rb:16:in `+'
app/models/message.rb:16:in `sms_message'
這是我message.rb
def sms_message
require "rubygems"
require "net/https"
require "uri"
require "json"
uname = "[email protected]"
hash = "54030737b105dsds7777 "
numbers = numbers
message = body
sender = "TXTLCL"
requested_url = 'http://api.textlocal.in/send/?' + "username=" + uname + "&hash=" + hash + "&numbers=" + numbers + "&message=" + body + "&sender=" + sender
uri = URI.parse(requested_url)
http = Net::HTTP.start(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
res = http.request(request)
response = JSON.parse(res.body)
puts (response)
end
def message_number
numbers = Student.new do |u|
u.phone1 = numbers
end
end
感謝您的回答,但我仍然**沒有收件人指定**爲:{「errors」=> [{「code」=> 4,「message」=>「沒有指定收件人」}],「狀態「=>」失敗「} – Dhanshree
啊。這可能是因爲網址 –
中的零值,如果值爲'nil',則可以'返回' –