AlexNikolaev94 AlexNikolaev94 - 2 months ago 23
Ruby Question

Cannot start Rack server because of NoMethodError

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

facebook-messenger
gem. Here's what I've got in my
config.ru
:

require './app'
require_relative 'bot'

require 'facebook/messenger'
include Facebook::Messenger


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


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

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


What can be the reason of this error?

Answer Source

Content of config.ru 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 config.ru.