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

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