Model Attributes

I'm having trouble with a model:

class Job < ActiveRecord::Base   belongs_to :company   belongs_to :city   belongs_to :region   belongs_to :country   belongs_to :department   belongs_to :user

  has_many :comments

  accepts_nested_attributes_for :city, :allow_destroy => :false   accepts_nested_attributes_for :region, :allow_destroy => :false   accepts_nested_attributes_for :country, :allow_destroy => :false   accepts_nested_attributes_for :company, :allow_destroy => :false   accepts_nested_attributes_for :department, :allow_destroy => :false end

I'm trying to create a form with nested attributes but whenever I call it complains that is nil.

You have a nil object when you didn't expect it! The error occurred while evaluating

Here is the associated controller code:

  def new     @job =   end

It would appear that I am wrong in my assumption that the relation in the model allows me to treat city as an attribute. How would I go about making this work?

I'm having trouble with a model: def new @job =


The magically created methods are @job.build_city etc.


Thank you much, that did the trick.

Fred's got the answer on this one, but holy database normalization Batman! A 'country' string field is enough for most people...

--Matt Jones