Forum: Ruby on Rails Add member variable to ActiveRecord model

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
74592905ef38cd087e5b73c0955aaa18?d=identicon&s=25 Martin Smith (Guest)
on 2006-05-04 21:25
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:       <label for="entity_name">Name</label>
  108:       </span>
  109:       <span class="forminput">
  110: <%= text_field 'entity', 'name'  %>
  111:       </span>
  112: </div>
  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
This topic is locked and can not be replied to.