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 8679865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:05:42+00:00 2026-06-12T21:05:42+00:00

I have a Rails model and in one of the methods I am generating

  • 0

I have a Rails model and in one of the methods I am generating a pdf using prawn like so;

class Report < ActiveRecord::Base

  def pdf_output
    Prawn::Document.new do
      text "Start date: #{start_date.strftime('%e %b %Y').squish}"
    end
  end

end

In that text method I am trying to output the start_date attribute of my report model. Instead I get the following error

NoMethodError in ReportsController#show

undefined method `start_date' for #<Prawn::Document:0x007fdafbce6930>

So my start_date method is referring to my Document object instead of my Report object. How do I access the variables and methods of my report object from inside this block?

  • 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-12T21:05:43+00:00Added an answer on June 12, 2026 at 9:05 pm

    The usual JavaScript trick should work:

    def pdf_output
      report = self
      Prawn::Document.new do
        text "Start date: #{report.start_date.strftime('%e %b %Y').squish}"
      end
    end
    

    Just grab a reference to the self you need so that you don’t have to worry about what Prawn is doing to self inside your block.

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

Sidebar

Related Questions

I have the following rails model: class Customer < ActiveRecord::Base attr_accessible :firstname, :lastname, :email,
I am using Rails and ActiveRecord. I have carrierwave mounted on one of the
I have the model Post: class Post < ActiveRecord::Base has_one :location, :dependent => :destroy
In my Rails app, I have a model Page which represents one HTML article
i have the following code in the rails company model: class Company include Mongoid::Document
I have a Rails engine that defines a class method top(count) on a model
I have been using Rails for over 4 years so obviously I like Rails
I have this class in a ruby on rails application class ChartData def self.user_logs_by_day(logs)
I am using Carrierwave to upload the imgae, i have used in one model,
Im using Rails 2.3.5 and I have a model, let's call it Post. I

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.