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