如何验证发送哈希数组的number_field_tag?

时间:2019-07-08 18:50:28

标签: ruby-on-rails ruby

我有一个number_field_tag这样的:

`number_field_tag "i_quantity[id]"`

如何在模型上验证此输入?

我尝试过这样的事情:

在视图中:     <%= number_field_tag "i_quantity[#{i.id}]" %>

在控制器中:

    def stock_params
        params.require(:stock).permit(i_quantity:{})
    end

在模型中:     `验证:i_quantity,状态::true``

查看

FORM TAG METHOD PUT

<% @inventario.each do |i|%>
<tr> 
  <td class="tabla-uno"> <%= i.article.id %> </td>
  <td class="tabla-uno"> <%= i.article.user.name %> </td>
  <td class="tabla-uno"> <%= i.article.name %> </td> 
  <td class="tabla-uno"> <%= i.article.description %> </td>
  <td class="tabla-uno"> <%= i.article.category %> </td>
  <td class="tabla-uno"> <%= i.article.subcategory %> </td>
  <td class="tabla-uno"> <%= number_to_currency(i.quantity_existent, 
  unit:"", precision: 0) %> 
   </td>
   <td class="tabla-uno"> <%= number_to_currency(i.quantity_request, 
   unit:"", precision: 0) %> 
   </td>
   <td class="tabla-uno"> <%= number_to_currency(i.article.quantity, 
   unit:"", precision: 0) %> 
   </td>
   <td class=""> <%= number_to_currency(i.article.price, unit: "$", 
   precision: 2) %> 
   </td>
   <td class=""> <%= number_field_tag "i_quantity[#{i.id}]", nil, {in: 
   0.. (i.article.quantity), class:"form-group", style:"width: 75px"}%> 
   </td>
</tr>
<% end %>

控制器:

    def stock_params
      params.require(:stock).permit(:quantity_existent, :quantity_request, 
                                    :user_id, i_quantity:{})
     end

型号:

`validates :i_quantity, presence: :true``

我想验证number_field_tag“ i_quantity [id]”

0 个答案:

没有答案