title: Validations in form_tag
body: <p>In my online shop I want to have validation before adding a product to the cart </p>
  
  <p>my order_item form is in the product show</p>
  
  <p>I want to force the user to select  a size, and display an <strong>error message</strong> if no size chosen ?</p>
  
  <p>Size is a nested attributes of products</p>
  
  <p>How I am supposed to write it? </p>
  
  <pre><code>&lt;%= form_tag clients_order_items_path, input_html: {id: "orderform"} do %&gt;
      &lt;%= hidden_field_tag :product_id, @product.id %&gt;
      &lt;%= hidden_field_tag :user_id, @token %&gt;
      &lt;%= hidden_field_tag :quantity, 1 %&gt;            
      &lt;%= select_tag :size_id, options_from_collection_for_select(@product.sizes.where('quantity &gt;=1'), :id, :size_name), prompt: "Your Size", class: 'form-control custom-select'%&gt;  
  &lt;%= submit_tag "Add to cart", class: "btn-main", id: "add_to_cart" %&gt;
  </code></pre>
  
    
  
  <p>here is the OrderItemsController with the create method: </p>
  
  <pre><code> def create
      @item = current_cart
      @size = Size.find(params[:size_id])
  
      if @size.quantity &gt;= params[:quantity].to_i
  
        current_cart.add_item(
          product_id: params[:product_id],
          quantity: params[:quantity],
          size_id: params[:size_id],
        )
  
        redirect_to clients_cart_path
      else
        redirect_to clients_product_path(Product.find(params[:product_id]))
  
      end
    end
  </code></pre>