简体   繁体   中英

why am i getting “undefined method `strip' for nil:NilClass” when i'm not calling the strip method?

I'm building a rudimentary app using the Twilio API, and have reached a block when using figaro to store account_sid and auth_token as environment variables in application.yml.

In my controller I have:

require 'twilio-ruby'
require 'figaro'
class TwilioController < ApplicationController

def voice   
account_sid = ENV["TWILIO_ACCOUNT_SID"]
auth_token = ENV["TWILIO_AUTH_TOKEN"]
@client = Twilio::REST::Client.new account_sid, auth_token

message = @client.account.sms.messages.create(:body => "Hello",
:to => "+12345678",
:from => "+12345678")
puts message.sid
end
end 

And in config/application.yml I have:

# TWILIO_ACCOUNT_SID: 1234567890
# TWILIO_AUTH_TOKEN: 1234567890

The program works as intended when I replace the env variables with actual values, so the most I'm able to grasp at the moment is that something is preventing those variables from being set.

I just upgraded from Rails 4.2 to Rails 5 and started getting this error.

For me, it was because a newer HAML version was no longer tolerant of a pre-existing empty javascript block.

:javascript

I deleted the ':javascript' line and everything was fine afterwards.

move constants to development.rb

and then just:

account_sid = TWILIO_ACCOUNT_SID

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM