I'm working on a ruby on rails app, where I have a model called categories with a field called "order_point", even though the "order_point" field shouldn't be of unique (different) value per record,
I want to create a form where I update multiple records's order_point attribute, and I want to make the form accept only the entered values of order_point, only if the the values are different ...
for example: I have categories A, B, and C, I want to create a form to input and update categories A,B,C at once, but if the entered order_point values of any of the 3 categories are the same, then the form should not submit (for example A= 3, B= 2, c=2).
I created the form the could update multiple records values at once using f.number_field which is nested in fields_for, here's my code:
<section class="container page-container">
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Arabic Name</th>
<th>Order Strength</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<%= form_tag admin_category_submit_order_categories_path, method: :post do %>
<% @categories.each do |category| %>
<tr>
<td><%= category.name %></td>
<td><%= category.ar_name %></td>
<td>
<%= fields_for "categories[]", category do |f|%>
<%= f.number_field :order_point, value: category.order_point, in: [email protected]+1 %>
<% end %>
</td>
</tr>
<% end %>
<div class="col-md-12">
<%= submit_tag("Update", { class: "btn btn-primary pull-right"}) %>
</div>
<% end %>
</tbody>
</table>
</section>
and here's a screenshot:
knowing that order strength is the order_point attribute
any solutions?
