Add member variable to ActiveRecord model


#1

Hi,

I have an addition member variable (no DB column) that I would like on
my model called postcode.

To make it available to the view when creating a new record I have added
the following:

def initialize
@postcode = “”
end

But now all the other members on my model (the ones that should be there
after Model.new) are gone, and the view reports a nil error…

You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.include?

Extracted source (around line #110):

107: Name
108:
109:
110: <%= text_field ‘entity’, ‘name’ %>
111:

112:
113:

If I remove the initialize method they reapear, but then, of course,
postcode is nill and the rendering fails with the same error.

Martin