【发布时间】:2015-07-29 01:05:19
【问题描述】:
我在让helpers 使用模块化 Sinatra 应用程序时遇到了一些麻烦。我有一个主控制器和一堆从它继承的其他控制器。所以/ 映射到Root,/auth 映射到Auth,等等。
主模块:
require 'sinatra/base'
# Lots of other requires
# Helper
module Utils
def test
puts "Test helper"
return 'test'
end
end
# Main app
class Application < Sinatra::Base
helpers Utils
# Lots of config
end
“控制器”继承Application,如:
class Root < Application
get '/' do
puts Utils # Exists
puts Utils.test # Breaks
# view() Defined directly in `Application`, runs slim
view :index
end
end
这会导致:
NoMethodError at /
为 Utils:Module 调用私有方法 `test'
有点难过。有什么帮助吗?
【问题讨论】:
标签: ruby sinatra rack view-helpers