Rails 3 Nested Models unknown attribute Error

前端 未结 4 1966
时光取名叫无心
时光取名叫无心 2021-01-03 03:49
  • I have a model \"Issue\" and a nested Model \"Relationship\"
  • In the issue.rb I have mentioned:

    has_many :relationships, :dependent => :d         
    
    
            
4条回答
  •  离开以前
    2021-01-03 04:31

    By using accepts_nested_attributes, you have created a setter method relationship_attributes=.

    There are a couple of things I noticed that need to change.

    You don't need to set

    @relationship = @issue.relationships.build
    

    Your form should be the following (you have f.fields_for :relationship)

    = form_for @issue do |f|
    
      # your issue fields here
    
      = f.fields_for :relationships do |r|
    
        # your relationship fields here
    

    The beauty here is that you won't have to set any ids or anything.

提交回复
热议问题