Can non-ActiveRecord variables be temporarily stored in a class?

I’m creating a PDF directory using PDF::Writer.

The directory has a few pieces.

  • The photo directory is sorted by group
  • The appendix is sorted by last name

I want the appendix to show the page number on which the person is
printed, but I don’t want to store that in the database.

I would like to do this:
contact.page_number = page_number
contacts << contact

but currently I’m doing this
tuple[:contact => contact, :page_number => page_number]
contacts << tuple

On Aug 23, 10:41 pm, CoolAJ86 [email protected] wrote:

I’m creating a PDF directory using PDF::Writer.

The directory has a few pieces.

  • The photo directory is sorted by group
  • The appendix is sorted by last name

I want the appendix to show the page number on which the person is
printed, but I don’t want to store that in the database.

An activerecord object is a normal ruby object - it can have non
database store instance variables if you want.

Fred

The directory has a few pieces.

  • The photo directory is sorted by group
  • The appendix is sorted by last name

I want the appendix to show the page number on which the person is
printed, but I don’t want to store that in the database.

An activerecord object is a normal ruby object - it can have non
database store instance variables if you want.

but when I do this:
contact.page_number = page_number
where page_number doesn’t exist in db/migrate/001_create_contacts.rb
or app/model/contacts.rb
I get this:
undefined method `page_number=’ for #Contact:0xb6bbb5b4

On Aug 25, 6:38 pm, CoolAJ86 [email protected] wrote:

but when I do this:
contact.page_number = page_number

Well yes - you still need to write the accessor methods to store you
instance variables (attr_accessor is probably enough).

Fred

Well yes - you still need to write the accessor methods to store you
instance variables (attr_accessor is probably enough).

Fred

That makes sense. Thanks.

I had my JavaScript thinking cap on when I was doing this… thinking
to create accessors out of thin air.

I also just found out that the virtual accessors are accessors, not
class variables.
return @updated_at # always null
return updated_at # works

2009/8/30 CoolAJ86 [email protected]:

I also just found out that the virtual accessors are accessors, not
class variables.
return @updated_at # always null
return updated_at # works

Don’t understand this.
As I understand it if you have
attr_accessor :my_var
then @my_var will access the variable (but this may only be written
inside the class)
and my_var is a method (well two methods actually) that may be used
externally to read/write to @my_var so you can say
my_object.my_var = 1
x = my_object.my_var

If you use my_var (no @) inside the class this should work but it is
calling the accessor methods rather than directly accessing @my_var

Colin

2009/8/30 Frederick C. [email protected]:

Fred

Don’t understand this.

I think what the previous poster has realised is that activerecord
attributes are not stored inside individual instance variables.

Ah, yes

Colin

Maybe this is useful

http://forums.site5.com/showthread.php?t=18522

On 30 Aug 2009, at 09:17, Colin L. wrote:

I had my JavaScript thinking cap on when I was doing this… thinking
to create accessors out of thin air.

I also just found out that the virtual accessors are accessors, not
class variables.
return @updated_at # always null
return updated_at # works

Don’t understand this.

I think what the previous poster has realised is that activerecord
attributes are not stored inside individual instance variables.

Fred