Question

I'm new to ruby and ruby on rails and having trouble setting up Twilio to send text messages.

So far I have the following code in my rails app: When I go to send the SMS message I get the following error:

Missing template twilio/send_text_message, application/send_text_message with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :slim, :coffee, :haml]}.

my initializer

#config/initializers/twilio.rb (removed keys)
require 'twilio-ruby'

  account_sid = "XXXXXXXXX"
  auth_token = "XXXXXXX"
  $twilio_phone_number = "+XXXXXXXXXX"

  $twilio_client = Twilio::REST::Client.new account_sid, auth_token

then added in the route

#routes.rb

post 'twilio/send_text_message' => 'twilio#send_text_message'

then i have my twilio controller

#twilioController
class TwilioController < ApplicationController

  def index
  end

  def send_text_message
  end
end

and in my view I've set up a form for a user to enter a message that gets sent to my phone (because i'm in trial mode and it's verified)

#ShareWithWorld.html.slim

= form_for :twilio, url: '/twilio/send_text', method: :post do |f|
  =f.text_field "Hey"
  =f.submit "Send Text"
Was it helpful?

Solution

The reason you're getting that error is the fact you have no view to be rendered, e.g. app/views/twilio/send_text_message.html.slim.

If the code comes to the end of the action without an interrupt, it will try and render the associated view.

class TwilioController < ApplicationController
  def send_text_message
    $twilio_client.account.messages.create(
      :from => '+14159341234',
      :to => '+16105557069',
      :body => ..params from form..
    )

    redirect_to root_path, notice: 'Your SMS has been sent' # This is the interrupt that will make it so it doesn't try to render the view
  end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top