国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

ruby - how to update submodels in rails
習(xí)慣沉默
習(xí)慣沉默 2017-05-17 10:02:06
0
1
1212

For example, parent model article

子模型  評(píng)論
一篇文章有許多評(píng)論,但是我發(fā)現(xiàn)評(píng)論寫錯(cuò)了 需要對(duì)評(píng)論進(jìn)行修改,這個(gè)需要如何做呢?

ParentModel

class CodeSnippet < ApplicationRecord
  has_many :annotations, dependent: :destroy
  accepts_nested_attributes_for :annotations ,update_only: true ,reject_if: :all_blank, allow_destroy: true
end

SubModel

class Annotation < ApplicationRecord
  belongs_to :code_snippet
end

Update child Model form

<%= form_for(@code_snippet) do |f| %>


    <%= f.fields_for :annotation,method: :patch do |builder| %>

        <p>
          <%= builder.label :user %><br>
          <%= builder.text_field :user %>
        </p>

        <p>
          <%= builder.label :line %><br>
          <%= builder.text_field :line %>
        </p>

        <p>
          <%= builder.label :body %><br>
          <%= builder.text_area :body %>
        </p>

        <p>
          <%= builder.submit %>
        </p>
    <% end %>
<% end %>

No update after clicking

習(xí)慣沉默
習(xí)慣沉默

reply all(1)
滿天的星座

Controller needs to do the corresponding processing, try to use save when saving code_snippet! Maybe you can see some problems

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template