Determine what to print using wicked_pdf on ruby on rails

0

I have a view of the data of a person (contact data, address, work data, medical data, etc.). At the moment I can convert everything I have in the PDF into PDF, but what I need is that when I press the button to convert to PDF I will see a screen (it can be a modal), where by means of checks I can choose which sections of my view to print.

Currently for printing I use the def show where I have defined the parameters to convert a file list_pdf.pdf.erb in pdf with the data of the view.

I use the gem wicked_pdf in rails 4 .

[updated]

I have the following ...

controller user

def show
          respond_to do |format|
          format.html
          format.pdf do
          render :pdf         => "file_name",

      end
    end
  end

# views / user / show.html.erb

<div>
            ...
            <h2><%= @user.last_name %> <%= @user.name %></h2>
            ...
        </div>
        #boton activa modal
        <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#miModal">
        #el modal
        ...
          <div class="modal-body">
                          <%= form_for employee_path do %>
                              Area 1
                              <%= check_box_tag :area1 %>
                              Area 2
                              <%= check_box_tag :area2 %>

                          <% end %>
                        </div>

                        <div class="modal-footer">
                                #boton que imprime
                                 <%= link_to user_path(  format: :pdf), :target => '_blank', class: 'btn btn-default' do %>
                      Imprimir <span>
                      <i class="fa fa-print " aria-hidden="true"></i></span>
                        <%end%>
         </div>
         ---

show.pdf.erb

...

<% if params[:area1]%>
    <div>
            ..bloque
    </div>
    <%end%>

in the controller I tried and I can not recover the value of params [: area1]. greetings

    
asked by sandovalgus 25.10.2016 в 13:34
source

1 answer

0

I've never done something like that with wicked_pdf , but what I can think of is that on your form you have something like:

<%= form_tag pdf_download_path do %>
  Area 1
  <%= check_box_tag 'area1' %>
  Area 2
  <%= check_box_tag 'area2' %>
  <%# etc... %>
<% end %>

And then in the template of your pdf you decide through the chosen parameters which is the section of the pdf to show:

<% if params[:area1] %>
  <%# contenido de tu area 1 del pdf %>
<% end %>
<% if params[:area2] %>
  <%# contenido de tu area 2 del pdf %>
<% end %>
<%# etc... %>

To do it in a modal, you can use the integrated ones in bootstrap .
You tell me how it goes with that. Greetings

    
answered by 25.10.2016 / 16:41
source