다른 파일에 모듈이 필요한 Sinatra 앱이 있습니다. 해당 모듈에서 Sinatra 명령을 사용할 때 NoMethodError
이 표시됩니다 (예 : redirect "http://facebook.com"
). 문제를 설명하기 위해, 나는 단순화 된 버전 만든 :Sinatra 명령이 모듈에서 작동하지 않습니다.
--- mainapp.rb ---
#config
require './redirector.rb'
get '/' do
Redirector::redirect_to_stackoverflow
end
을 --- redirector.rb ---
module Redirector
require 'sinatra'
def self.redirect_to_stackoverflow
redirect "http://stackoverflow.com"
end
end
- - config.ru ---
require 'rubygems'
require 'sinatra'
require File.dirname(__FILE__) + "/ptt.rb"
run Sinatra::Application
무엇이 잘못 되었습니까? 내가 뭔가를 제대로 요구하지 않은 곳이 있습니까?