Ruby/Sinatra:将 URL 变量传递给 .erb 模板

Ruby/Sinatra: Passing a URL variable to an .erb template

我正在使用 Padrino,我想从 URL 中取出参数并在 .erb 模板中使用它们。

在我的应用程序设置中,我有:

get '/testpage/:id' do
  userID = params[:id]
  render 'test/index'
end

在我的 test/ 文件夹中,我有 index.html.erb 已成功呈现,对于 url 如 http://localhost:9000/testpage/hello123

但是,我尝试在页面上打印 params[:userID]

<%= @userID %>

页面的其余部分呈现良好,但找不到 hello123。当我尝试 <%= userID %> 我得到 undefined local variable or method `userID' for #<stuff>

我在这里错过了什么?

只是猜测,因为我从未使用过 Padrino,但如果它像 Rails 那样工作,这可能会对您有所帮助:

get '/testpage/:id' do
  @userID = params[:id]
  render 'test/index'
end