ruby - NoMethodError at / undefined method `include?' for nil:NilClass -


i'm trying build sinatra ruby app. having trouble undefined method error. keep trying utilize method_missing i'm afraid keep messing syntax. write if else statement specifying if @x returns nil? i'm kinda of new , use help. thanks!

my rb file

        '/'   @x = params[:body]   session[:a] = (params[:body].partition(' ').last.to_f / 2.2) * 0.58 if @x.include?("weight")   session[:b] = params[:body].partition(' ').last.to_f * 0.9672 if @x.include?("drinks")   session[:c] = params[:body].partition(' ').last.to_f * 0.015 if @x.include?("time")   session[:d] = params[:body].partition(' ').last if @x.include?("tweet")   bac = round_to_precision(session[:b]/session[:a]-session[:c],3)   timeleft = 40*(bac-0.08)/0.01   hoursleft = (timeleft / 60).floor   minutesleft = (timeleft - (hoursleft.floor * 60)).floor    subliml = twilio::twiml::response.new |r|     if bac >= 0.08       r.sms "your bac of #{bac} on federal limit of 0.08.  #{hoursleft} hours , #{minutesleft} minutes until under limit. text tweet anonymously exclaim inebriation!"     elsif bac.between?(0,0.08)       r.sms "your bac of #{bac} under limit"     elsif bac.between?(-0.5,0)       r.sms "have beer"     end   end    twiml = twilio::twiml::response.new |r|       r.sms "hey there! welcome bac app! please text weight followed weight"     end   himl = twilio::twiml::response.new |r|     r.sms "cool, text drinks followed how many drinks you've had"     end   timl = twilio::twiml::response.new |r|     r.sms "almost there!!! text time followed how long have been drinking"     end   swiml = twilio::twiml::response.new |r|       r.sms "hmm, try else"     end     if @x.include?("drunk")       twiml.text     elsif @x.include?("weight")       himl.text     elsif @x.include?("drinks")       timl.text     elsif @x.include?("time")       subliml.text      elsif @x.include?("tweet")       request.set_form_data(         "status" => session[:d])       request.oauth! http, consumer_key, access_token       http.start       response = http.request request     end end 

it looks you're calling include? on @x. in instances, must nil. if it's doing this, you're getting wrong parameter.

you can check this:

if @x.nil?   # smart, maybe redirect different page end 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -