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

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>

> > 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

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

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

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

Don't understand this.

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

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

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