Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8482421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:49:25+00:00 2026-06-10T19:49:25+00:00

In my controller, i have a method defined as: def self.store_pdf(id) … end in

  • 0

In my controller, i have a method defined as:

def self.store_pdf(id)
...
end

in that method, I need to call render_to_string to render the correct file / layout:

render_to_string(
    :action => "../view/current_version/show.pdf.erb", 
    :layout => false)

but because render_to_string is both an instance method and protected, I need to do the following:

me = self.new # self is the cortroller
me.send(:render_to_string,
    :action => "../view/current_version/show.pdf.erb", 
    :layout => false)

but then there are dependencies such as the response object that render_to_string needs to work, as shown here: http://apidock.com/rails/ActionController/Base/render_to_string

So, I began adding them

me.send(:response=,  ActionController::Response.new)

But, more and more of the global instance variables need to be defined, and I decided it was too much work just to try to get one static method to work.

The method needs to be static, so that delayed_job can run the method in the background at a later time.

Anyone have an idea as to how to pull this off?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:49:27+00:00Added an answer on June 10, 2026 at 7:49 pm

    You can read erb via ERB if you are not using any rails helper,If you are using any rails helper then include Rails helper.
    you can refer using here or

    require 'erb'
    class PdfRender
     #include ActionView::Helpers::OutputSafetyHelper
     #include helper if any is present any
     def self.render_pdf(id)
      #set any instance variable if you are using in pdf 
      content = File.read('path/of/erb/template')
      template = ERB.new(content) 
      # template content will give you text now you can render or generate pdf
      template_content = template.result(binding)
    
    
     end
    end 
    

    Note:
    replace h() with CGI.escapeHTML()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a controller method that is a little something like this: def suggestions
I have this method in my videos controller: def notifications erase_notification_count end It calls
Controller Call user = User.authenticate(params[:session][:email], params[:session][:password]) Authenticate Method in user.rb class << self def
I have a method defined in my controller that I am trying to create
I have a variable @products = Product.all defined inside new method in a controller.
I have a controller method that returns a jSON object and in one calling
i have a quetion about MVC routing. I have a controller method that is
I have defined a problems method in my Report model. I need to use
I have a method defined in application_helper.rb that returns a canonical URL based on
In my application controller, I have a method that is supposed to check for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.