How to add two parameters from the url
问题 How can I display in my web page the result of int1 + int2 ? And can I know if it's an integer or a string? Here is my code: require 'sinatra' get '/add/:int1/:int2' do puts #{params[:int1]} + #{params[:int2]} end 回答1: "#{params[:int1].to_i + params[:int2].to_i}" 回答2: you need to pass it in url http://yourdomain/add/2/3 #=> this will display 5 :int1 => 2, :int2 => 3 for embedding/interpolating variables use double quotes with puts puts "#{params[:int1]} + #{params[:int2]}" 回答3: Here is