Passing parameters to erb view

后端 未结 3 858
孤街浪徒
孤街浪徒 2020-12-25 10:39

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]}!\"
en         


        
3条回答
  •  醉酒成梦
    2020-12-25 11:00

    just pass the :locals to the erb() in your routes:

    get '/hello/:name' do
        erb :hello, :locals => {:name => params[:name]}
    end
    

    and then just use it in the views/hello.erb:

    Hello <%= name %>
    

    (tested on sinatra 1.2.6)

提交回复
热议问题