0

error: "uninitialized constant TwilioCapability"

Twilio capability token generate issue on live site and staging this is working properly.

This is my code of generate Twilio Capability token

class Twilio::TokenController < ApplicationController
  skip_before_filter :verify_authenticity_token

  def generate
    token = ::TwilioCapability.generate("#{params[:appointment_id]}#{params[:from_type]}")
    render json: { token: token }
  end
end

twilocapabilty.rb file code

class TwilioCapability
  def self.generate(id)
    account_sid = ENV['TWILIO_ACCOUNT_SID']
    auth_token  = ENV['TWILIO_AUTH_TOKEN']
    capability = Twilio::Util::Capability.new account_sid, auth_token

    application_sid = ENV['TWIML_APPLICATION_SID']
    capability.allow_client_outgoing application_sid
    capability.allow_client_incoming id

    capability.generate
  end
end
Hardika Desai
  • 83
  • 1
  • 14

1 Answers1

0

Twilio developer evangelist here.

I believe there might be a couple of issues with this, mainly answered in this existing SO question.

Firstly, make sure that, if your class is called TwilioCapability then the file name matches it via the Rails naming rules. It should be called twilio_capability.rb.

Other than that, I guess you are keeping the file in the lib directory (so it should be lib/twilio_capability.rb). If you are not already autoloading files from lib in production, then you should add the following to your config/application.rb:

config.autoload_paths << Rails.root.join('lib')

Let me know if that helps at all.

philnash
  • 70,667
  • 10
  • 60
  • 88