2015-10-02 40 views
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>

我在这里错过了什么?

回答

3

只是一个猜测,因为我从来没有用过Padrino,但如果它的工作原理是Rails的这可能会帮助您:

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

这是烦人的简单修复。谢谢! – Jascination

+0

我很高兴这很容易,@Jascination! – chadoh