2015-10-02 33 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