【发布时间】:2016-07-11 19:10:00
【问题描述】:
我正在学习如何使用 Sinatra。我发现当我将对象作为本地人传递时,例如:
product = FetchProduct.new.call(id) #function finds exact Product instance
erb :"products/show", locals: { product: product }
我可以在我的视图中使用我声明的所有实例方法中的产品对象。但我不能使用任何类方法,任何尝试这样做都会给我未初始化的常量错误。如果我想使用Product.format_price(product.price) 方法应该怎么做?有没有办法将类方法传递给 Sinatra 视图?
【问题讨论】: