I'm trying to pass parameters to an erb view using Ruby and Sinatra.
For example, I can do:
get '/hello/:name' do
"Hello #{params[:name]}!"
end
How do I pass :name
to the view?
get '/hello/:name' do
erb :hello
end
And how do I read the parameters inside view/hello.erb?
Thanks!
Not sure if this is the best way, but it worked:
Then, I can access
:name
in hello.erb using the variable@name
just pass the :locals to the erb() in your routes:
and then just use it in the views/hello.erb:
(tested on sinatra 1.2.6)
You cannot do this in routes.
You want to set the params in the controller.
app/controllers/some_controller.rb
app/views/index.html.erb