title: Passing variables between routes in Sinatra
body: <p>I'm implementing sms-validation of registration on Sinatra site, and I got this code:
  </p>
  
  <pre><code>post '/reg' do
    phone = params[:phone].to_s
    code = Random.rand(1000..9999).to_s
    HTTParty.get('http://sms.ru/sms/send?api_id=' + api_id + phone + '&amp;text=' + code)
  end
  </code></pre>
  
  <p>This take users phone from <strong>post</strong> request, than generates 4 digit code, and sends code on number via <strong>get</strong> request to sms service. But, page doesn't reloading, because at that moment opens modal dialog, where user should type <em>code</em>. Button which opens modal simultaneously sends <strong>post</strong> via Ajax with this code:
  </p>
  
  <pre><code>$(document).ready(function(){
    $("#sendsms").click(function(){
      var phone = $("#phone").val();
      $.ajax({
        url: "/coop",
        data: {"phone": phone},
        type: "post"
      });
    });
  });
  </code></pre>
  
  <p>It would be strange to check user's code on client side, thats why I got this action route:
  </p>
  
  <pre><code>post '/coop/checkcode' do
    usrcode = params[:code]
    if code == usrcode
      redirect '/reg/success'
    else
      redirect '/reg/fail'
    end
  end
  </code></pre>
  
  <p>But I can't just take and type <em>code</em> var from first route in the <em>checkcode</em> route. But I need.</p>
  
  <p>Is there exists any possible way to pass that variable or implement this somehow other way?</p>
  
  <p>Thank you in advance.</p>