3

I'm using Padrino, and I want to take parameters out of URL and use them in an .erb template.

In my app setup I have:

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

In my test/ folder I have index.html.erb which is successfully rendered, for a url like http://localhost:9000/testpage/hello123.

However, I've tried printing the params[:userID] on the page with:

<%= @userID %>

The rest of the page renders fine but hello123 isn't anywhere to be found. When I try <%= userID %> I get undefined local variable or method `userID' for #<stuff>

What am I missing here?

thesecretmaster
  • 1,950
  • 1
  • 27
  • 39
JVG
  • 20,198
  • 47
  • 132
  • 210

2 Answers2

3

Just a guess, because I've never used Padrino, but if it works like Rails this may help you:

get '/testpage/:id' do
  @userID = params[:id]
  render 'test/index'
end
chadoh
  • 4,343
  • 6
  • 39
  • 64
0

In sinatra, it's just like this (see "Views/Templates" section):

get '/testpage/:id' do |id|
  erb :index, :locals => {:id => id}
end

The template is located in views/index.erb by default. It could be change.

somenxavier
  • 1,206
  • 3
  • 20
  • 43