call action from another action rails to save pdfs with prawn

461 Views Asked by At

I have an action to generate pdfs with prawn

def savepdfs
  respond_to do |format|
    format.pdf {} # Create PDF file and saves in /pdf/print.pdf.
    logger.info ":::::::::::::::::  PDF COVER PAGE CREATED  :::::::::::::::::"
  end
end

I don't want to show the pdf to the user . Instead I just want to call this from another action

def mainaction
    #I want to call something like savepdfs(:format => :pdf)
end

How do I do this ?

2

There are 2 best solutions below

3
On BEST ANSWER

Wrap it as a private controller method

def savepdfs
  respond_to do |format|
    format.pdf { generate_pdf } # Create PDF file and saves in /pdf/print.pdf.
    logger.info ":::::::::::::::::  PDF COVER PAGE CREATED  :::::::::::::::::"
  end
end

def mainaction
  generate_pdf
end

private

def generate_pdf
  # Create PDF file and saves in /pdf/print.pdf.
end
0
On

This is an XY Problem*. You don't want to call another action, you want to put business logic in the model where it belongs.

* http://www.perlmonks.org/index.pl?node_id=542341