accepts_nested_attributes_for with has_many => :through Options

后端 未结 7 1959
陌清茗
陌清茗 2020-12-08 10:10

I have two models, links and tags, associated through a third, link_tags. The following code is in my Link model.

Associations:

class Link < Acti         


        
7条回答
  •  一个人的身影
    2020-12-08 10:45

    Take a look at the line of your code

    <% f.fields_for :tags_attributes do |tag_form| %>
    

    You need to use just :tags instead of :tags_attributes. This will solve your issue

    Make sure that You have build links and tags in your controller like

    def new
      @link = @current_user.links.build
      @link.tags.build
    end
    

提交回复
热议问题