Ruby 方法范围如何工作?

发布于 2024-12-25 13:24:40 字数 258 浏览 2 评论 0原文

我使用sinatra,有一个问题无法解决,代码如下:

require 'sinatra'

def url(s)
    get  s do yield end
    post s do yield end
end

url '/' do
    erb :index
end

那么,程序提示: undefined method `erb' for main:Object

怎么办?

I use sinatra, and have a question that I can't solve, here is the code:

require 'sinatra'

def url(s)
    get  s do yield end
    post s do yield end
end

url '/' do
    erb :index
end

then, the program tips that: undefined method `erb' for main:Object

what should I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

揽清风入怀 2025-01-01 13:24:40

你可以尝试这样的事情:

require 'rubygems'
require 'sinatra'

def map_url(url, options={}, &block)
  get(url, options, &block)
  post(url, options, &block)
end

map_url '/' do
  erb :index
end

You could try something like this:

require 'rubygems'
require 'sinatra'

def map_url(url, options={}, &block)
  get(url, options, &block)
  post(url, options, &block)
end

map_url '/' do
  erb :index
end
养猫人 2025-01-01 13:24:40

您可能想看看 Sinatra Multiroute

You might want to take a look at Sinatra Multiroute.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文