Passing parameters to erb view

后端 未结 3 854
孤街浪徒
孤街浪徒 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 10:50

    get '/hello/:name' do
      "Hello #{params[:name]}!"
    end
    

    You cannot do this in routes.

    You want to set the params in the controller.

    app/controllers/some_controller.rb

    def index
        params[:name] = "Codeglot"
        params[:name] = "iPhone"    
        params[:name] = "Mac Book"      
    end
    

    app/views/index.html.erb

    <%= params[:name] %>
    <%= params[:phone] %>
    <%= params[:computer] %>
    

提交回复
热议问题