title: How do I Inject a JavaScript variable into Ruby code using HAML?
body: <p>I am trying to inject the <code>filename</code> JavaScript variable into my Ruby code like this:</p>
  
  <pre><code>"#{ajax_download_report_url(" + filename+ ")}"
  </code></pre>
  
  <p>It's a basic route URL but I need to pass this variable in HAML because I get it from this Ajax request:</p>
  
  <pre><code>:javascript
          var updaterId = setInterval(function() {
            $.ajax({
              url: #{admin_reports_url.to_json},
              dataType: "json",
              type:  "GET",
              data: {job_id: "#{job_id}"},
              success: function(response){
                var filename = response.file;
                switch(status) {
                  case 'failed':
                    $('.loader').hide();
                    clearInterval(updaterId);
                    alert(message);
                    break;
                  case 'completed':
                    $('.loader').hide();
                    clearInterval(updaterId);
                    location.href = "#{ajax_download_report_admin_reports_url(" + filename+ ")}";
                    break;
                }
              }
            })}, 1000);
  </code></pre>
  
  <p>Now I have an error:</p>
  
  <pre><code>ActionController::RoutingError - No route matches 
  {:controller=&gt;"admin/reports", :action=&gt;"ajax_download_report", :file=&gt;" + filename+ "}
  </code></pre>
  
  <p>which means that HAML can't properly evalute this code.</p>