For example, a parent model article
Sub-model review
There are many comments in an article, but I find that the comments are wrong and need to be revised. How do I do this?
Parent Model
class CodeSnippet < ApplicationRecord
has_many :annotations, dependent: :destroy
accepts_nested_attributes_for :annotations ,update_only: true ,reject_if: :all_blank, allow_destroy: true
end
Sub Model
class Annotation < ApplicationRecord
belongs_to :code_snippet
end
Update 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
The controller should do the corresponding processing, and try to use save when saving code_snippet! Maybe we can see some problems