I'm building a store in Rails that has a specific sales model. I need to allow a user to add only 3 items to his order per 30 days. The 30 days counter should start upon adding the first order\_item. Once 30 days expires, user would be able to add 3 orders. If 30 days didn't pass and for an example, user adds two order\_items he would still be allowed to add one more order\_item within 30 days. So as well if user tries to add more then 3 items to show an error message and disregard saving of the order\_items to current\_user's order.
When I submit a form for adding the order\_item to a order I'm getting this error:

```
ArgumentError (comparison of Date with nil failed):
  app/controllers/order_items_controller.rb:4:in `<'
  app/controllers/order_items_controller.rb:4:in `create'

```

order\_items\_controller.rb:

```
def create
      now = Date.today
      if (now - 30) < current_user.begin_date
         if current_user.order_counter >= 3
            # deal with the case that order should not be created, 
            # for example redirect
         else
           current_user.order_counter += 1
           current_user.save
         end
      else 
        current_user.order_counter = 1
        current_user.begin_date = now
        current_user.save
      end
      @order = current_order
      @order_item = @order.order_items.new(order_item_params)
      @order.user_id = current_user.id
      @order.save
      session[:order_id] = @order.id

      respond_to do |format|
        format.js { flash[:notice] = "ORDER HAS BEEN CREATED." } 
      end
    end

```

form:

```
 <%= form_for OrderItem.new,  html: {class: "add-to-cart"}, remote: true do |f| %>
<div class="input-group">
      <%= f.hidden_field :quantity, value: 1, min: 1 %>
      <div class="input-group-btn">
        <%= f.hidden_field :product_id, value: product.id %>
        <%= f.submit "Add to Cart", data: { confirm: 'Are you sure that you want to order this item?'}, class: "btn btn-default black-background white" %>
      </div>
    </div>
  <% end %>
</div>

```