This example shows a fairly simple way to add restrictions to the cocoon.
Add to your application.js (or another. Js file):

$('#products').cocoon_limiter()
In html markup (_form.html.haml in this example):
 ... any other markup ...
#products
  %h3 Products:
  %hr
  = f.simple_fields_for :products do |product|
    = render "product_fields", f: product
  .links
    = link_to_add_association f, :products, data: {:'cocoon-limit' => 5}, class: "btn" do
      You can add
      %b{data:{counter: ""}}
      items
And this is enough to get started.

Products:


x