Ondra
Ondra

Reputation: 3180

Get output of different controller action in rails3

For generating PDF from HTML, i need to fill a variable with output from another controller action output (HTML). Is there any elegant way, how to get this HTML?

Thanks

Upvotes: 2

Views: 421

Answers (2)

BitOfUniverse
BitOfUniverse

Reputation: 6021

You can use:

def print
  output = render_to_string(:action => :index)
end

in your controller.

Upvotes: 3

Kevin
Kevin

Reputation: 1855

You may abstract the code in that action into a shared method which would be called within your pdf-generating action.

After calling the shared method, you would get the html page content like this:

pdf_content = ERB.new(File.read("/path/to/that/erb.file")).result

Upvotes: 2

Related Questions