title: How to save many items on one form rails?
body: <p>I need to save many items to Cart on form, user enter quantity one form, and selected items goes to db, but now save only first entered quantity of item. Why?</p>
  
  <p>my form </p>
  
  <pre><code>&lt;%= form_for @cart_item do |f| %&gt;
  &lt;% @category.items.each do |item| %&gt;
  &lt;%= item.name %&gt;
  &lt;%= f.hidden_field :item_id, :value =&gt; item.id %&gt;
  
  &lt;%= f.text_field :qty %&gt;
  &lt;% end %&gt;
  &lt;%= f.submit %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>And controller
  cart_items_controller.rb</p>
  
  <pre><code>class CartItemsController &lt; ApplicationController
  
      before_action :set_cart, only: [:create]
  
  
      def create
          @cart_items = CartItem.create(cart_items_params)
          @cart_items.cart_id = @cart.id
          if @cart_items.save
          redirect_to :back
          else
              render root_path
          end
      end
  
      private
  
      def cart_items_params
          params.require(:cart_item).permit(:id, :qty, :item_id, :cart_id)
      end
  
      def set_cart
          @cart = Cart.find(session[:cart_id])
      rescue ActiveRecord::RecordNotFound
          @cart = Cart.create
          session[:cart_id] = @cart.id
      end
  
  end
  </code></pre>