3
我使用Padrino,我想从URL中提取参数并在.erb
模板中使用它们。Ruby/Sinatra:将URL变量传递给.erb模板
在我的应用程序的设置,我有:
get '/testpage/:id' do
userID = params[:id]
render 'test/index'
end
在我test/
文件夹我有index.html.erb
被渲染成功,对于像http://localhost:9000/testpage/hello123
的URL。
不过,我已经试过在页面上打印params[:userID]
有:
<%= @userID %>
页面的其余部分呈现正常,但hello123
是不是在任何地方被发现。当我尝试<%= userID %>
我得到undefined local variable or method `userID' for #<stuff>
我在这里错过了什么?
这是烦人的简单修复。谢谢! – Jascination
我很高兴这很容易,@Jascination! – chadoh