accepts_nested_attributes_for with has_many => :through Options

后端 未结 7 1946
陌清茗
陌清茗 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 11:06

    You need to build a tag in your controller or in the view

    def new
      @link = @current_user.links.build
      @link.tags.build
    end
    
    #in your view you can just use the association name
    <% f.fields_for :tags do |tag_form| %>
    
    0 讨论(0)
提交回复
热议问题