Reputation: 316
I am following a Twilio tutorial (HERE) to add voice and sms to my rails 4 and keep getting the same error...A 'To' phone number is required. I think I have a to number defined...no? I have included all the relevant code below. Thank you in advance. Would also like to note that client_phone is a column in the table...the client_phone is entered by the user and then the button is clicked to share it.
Controller:
def share_over_sms
twilio_sid = ENV["TWILIO_ACCOUNT_SID"]
twilio_token = ENV["TWILIO_AUTH_TOKEN"]
twilio_phone_number = ENV["TWILIO_PHONE_NUMBER"]
@twilio_client = Twilio::REST::Client.new twilio_sid, twilio_token
@twilio_client.account.sms.messages.create(
:from => "+1#{twilio_phone_number}",
:to => @client_phone,
:body => "This is a test."
)
end
Route:
get "share_over_sms"
View:
<%= link_to 'Share Text', share_over_sms_listing_collection_path(@listing_collection), class: "button btn-nklyn-dark btn-2x" %>
Error:
Upvotes: 0
Views: 699
Reputation: 3811
Mike, did you try Phil's suggestions from above? Using listing_collection_params["client_phone"]
instead of @client_phone
in the :to
parameter and using @twilio.messages.create
? The .sms.messages
endpoint in the API is deprecated.
I would also suggest taking a peek at the production ready code samples from tutorials like this one to compare the Rails setup.
Upvotes: 1