ruby - Nested Models Error in Rails 3 -


i have 2 models app , contact. app has has_one relationship contact. have declared accepts_nested_attributes_for clause in app model contact. now, in apps_controller, if use build method on app object, error the nil class, though had declared relationship.

app.rb

class app < activerecord::base   has_one :contact_person, :dependent => :destroy   accepts_nested_attributes_for :contact_person end 

contactperson.rb

class contactperson < activerecord::base   belongs_to :app end 

apps_controller.rb

def new   @app = app.new   @app.contact_person.build end 

could please point me out whether doing incorrectly. have used nested models before have not encountered error.

i supposed use @app.build_contact_person instead of @app.contact_person.build. in way, worked :)


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -