title: Quantity in Cart Model Basic Logic Ruby on Rails
body: <p>I am trying to apply some very basic logic to my view but am so far failing. </p>
  
  <p>What I would like to do is return item.discount_price if there are the following conditions:</p>
  
  <ol>
  <li>The item.product_id is equal to 1</li>
  <li>The Cart.item.quantity count is equal or higher than 2. </li>
  </ol>
  
  <p>Currently I have the following:</p>
  
  <p>Items Model</p>
  
  <pre><code>class Item &lt; ActiveRecord::Base
  belongs_to :product
  belongs_to :cart
  
  def price_check
  
      if  Item.product_id = 1 &amp;&amp; Item.quantity.count &gt;= 2 
          return Item.discount_price
      else
          return Item.unit_price
      end 
  
  end
  </code></pre>
  
  <p>end</p>
  
  <p>View</p>
  
  <pre><code>&lt;% for item in @cart.items %&gt;
  &lt;tr class="&lt;%= cycle :odd, :even %&gt;"&gt;
    ...
    &lt;td class="price"&gt;&lt;%= gbp(item.price_check) %&gt;&lt;/td&gt;
    ...
  &lt;/tr&gt;
  </code></pre>
  
    
  
  <p>The associations are as follows:</p>
  
  <pre><code>Cart - has_many :items
  Items - Belongs_to :cart and :products
  Products - has_ many :items
  </code></pre>
  
  <p>The error I keep receiving:</p>
  
  <pre><code> NoMethodError in Carts#show
  
  Showing C:/Sites/checkout/app/views/carts/show.html.erb where line #12 raised:
  
  undefined method `quantity' for #&lt;Class:0x50c3058&gt;
  
  Extracted source (around line #12):
  
  9:        &lt;tr class="&lt;%= cycle :odd, :even %&gt;"&gt;
  10:       &lt;td&gt;&lt;%=h item.product.name %&gt;&lt;/td&gt;
  11:       &lt;td class="qty"&gt;&lt;%= item.quantity %&gt;&lt;/td&gt;
  12:       &lt;td class="price"&gt;&lt;%= gbp(item.price_check) %&gt;&lt;/td&gt;
  13:       &lt;td class="price"&gt;&lt;%= gbp(item.full_price) %&gt;&lt;/td&gt;
  14:       &lt;td&gt;&lt;%= button_to 'Remove', item, :method =&gt; :delete %&gt;&lt;/td&gt;
  15:       &lt;/tr&gt;
  
  app/models/item.rb:12:in `price_check'
  app/views/carts/show.html.erb:12:in `block in _app_views_carts_show_html_erb___389237738_48997308'
  app/views/carts/show.html.erb:8:in `_app_views_carts_show_html_erb___389237738_48997308'
  </code></pre>
  
  <p>Any help people can offer to fix this would be much appreciated! Thanks E</p>