Fred's got the answer on this one, but holy database normalization Batman! A 'country' string field is enough for most people...
--Matt Jones On Aug 22, 1:22 pm, Glen <[email protected]> wrote: > 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 > @job.city.build it complains that @job.city is nil. > > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.build > > Here is the associated controller code: > > def new > @job = Job.new > > @job.city.build > @job.region.build > @job.counrty.build > @job.department.build > @job.company.build > 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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

