Submission form review of Ajax in Rails. How to clean after shipping if multiple forms?

On the page there are several items to each have a comment form and send comments.
How to make the form after sending a comment via Ajax again became empty.
This option only works for the first form:
$("#comment_content").val(");

For each shape needs its own unique id, but how to do it?
You can specify unique id for div of the form, id type="comments_form_<%= item.id % > but the above method only works for forms but not for div.
Maybe there are other options?
July 9th 19 at 13:28
2 answers
July 9th 19 at 13:30
Solution
Figured out
$("#item_<%=@item.id%>_comments_form").find("#comment_content").val(");

item_<%=@item.id%>_comments_form is the id inside of which is a submission form review comment_content id
July 9th 19 at 13:32
And you have all the input fields have the same id? Notice anything odd?
Here's my comment form:
<%= form_for :comment, url:list_comments_path(@list),remote: true do |f| %>
<%= f.text_field :content, class: "form-control", placeholder:"Your comment" %>
<%= f.hidden_field :item_id, :value => item.id %>
<%= f.submit "Submit",class: "btn btn-default" %>
<% end %>

It will be rendered under each item has id="comment_content" - Mandy_Swaniaws commented on July 9th 19 at 13:35
In a correctly written HTML document MUST NOT BE elements with the same ID. It is therefore an ID that is the unique identifier of the element in the Dom structure. - lily.Kozey commented on July 9th 19 at 13:38

Find more questions by tags Ruby on Rails