title: How to respond with format.pdf in rails 5
body: <p>Im trying to use jquery to get a controller action which shows a pdf page. Before the javascript way, the rails way worked:</p>
  
  <p><strong>Show.html.erb</strong></p>
  
  <pre><code>&lt;%= link_to "Get PDF", client_path(@client.id, format: :pdf) %&gt;
  </code></pre>
  
  <p>The issue is, I need some params that I get from javascript so a work around was to use ajax to make the request:</p>
  
  <p><strong>js:</strong></p>
  
  <pre><code>$.ajax({
    url: "/clients/" + clientId + ".pdf",
    type: 'POST', // Ive also tried GET and created a post route in routes.rb
    data: { //...
    },
    success: function(data, xhr) {
      //...
      console.log('Success.....');
    },
    error: function() {
      console.log("Error....")
    }
  
  });
  </code></pre>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>respond_to :html, :xml, :json
  
  def show
     respond_with do |format|
        format.pdf do
          render pdf: "demopdf",
                 template: "clients/show.pdf.html.erb",
                 locals: {:client =&gt; @client}
        end
      end
  end
  </code></pre>
  
  <p>If I click my rails button, I get the pdf view but not so with a normal button with a button click function. How to do this with ajax? I got the success log but that's it.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>How to get <code>Bar</code> to my controller? I need to have <code>Bar</code> in my pdf?</p>
  
  <p><strong>show.html.erb:</strong></p>
  
  <pre><code>&lt;p id="foo"&gt;&lt;/p&gt;
  </code></pre>
  
  <p><strong>js:</strong></p>
  
  <pre><code>$("#foo").text("Bar");
  </code></pre>
  
  <p>So basically I need to pass few params in:</p>
  
  <pre><code>&lt;%= link_to "Get PDF", client_path(@client.id, format: :pdf) %&gt;
  </code></pre>