AlexNikolaev94 AlexNikolaev94 - 1 year ago 106
Ruby Question

Cannot start Rack server because of NoMethodError

I'm writing a tiny Sinatra application (Facebook Messenger bot), so I'm using

gem. Here's what I've got in my

require './app'
require_relative 'bot'

require 'facebook/messenger'
include Facebook::Messenger

map '/webhook' do
run Sinatra::Application
run Facebook::Messenger::Server

But anytime I try to launch my server with
rackup -p 5000
command, it returns me the following error:

/chatbot/ `block in <main>': undefined method `include' for #<Rack::Builder:0x007feb32926e70> (NoMethodError)

What can be the reason of this error?

Answer Source

Content of file is handled by Rack::Builder, not by Ruby itself. Specificaly the include line is evaluated in context of Rack::Builder and that gives you the undefined method. According to the rest of the code, you dont need to include it as you use full path to the inner Module/Class

run Facebook::Messenger::Server

If you realy need to include it, do so in separete (ruby) file and require that file in

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download