Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8770345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:32:36+00:00 2026-06-13T17:32:36+00:00

I am trying to apply some very basic logic to my view but am

  • 0

I am trying to apply some very basic logic to my view but am so far failing.

What I would like to do is return item.discount_price if there are the following conditions:

  1. The item.product_id is equal to 1
  2. The Cart.item.quantity count is equal or higher than 2.

Currently I have the following:

Items Model

class Item < ActiveRecord::Base
belongs_to :product
belongs_to :cart

def price_check

    if  Item.product_id = 1 && Item.quantity.count >= 2 
        return Item.discount_price
    else
        return Item.unit_price
    end 

end

end

View

<% for item in @cart.items %>
<tr class="<%= cycle :odd, :even %>">
  ...
  <td class="price"><%= gbp(item.price_check) %></td>
  ...
</tr>

The associations are as follows:

Cart - has_many :items
Items - Belongs_to :cart and :products
Products - has_ many :items

The error I keep receiving:

 NoMethodError in Carts#show

Showing C:/Sites/checkout/app/views/carts/show.html.erb where line #12 raised:

undefined method `quantity' for #<Class:0x50c3058>

Extracted source (around line #12):

9:        <tr class="<%= cycle :odd, :even %>">
10:       <td><%=h item.product.name %></td>
11:       <td class="qty"><%= item.quantity %></td>
12:       <td class="price"><%= gbp(item.price_check) %></td>
13:       <td class="price"><%= gbp(item.full_price) %></td>
14:       <td><%= button_to 'Remove', item, :method => :delete %></td>
15:       </tr>

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'

Any help people can offer to fix this would be much appreciated! Thanks E

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:32:38+00:00Added an answer on June 13, 2026 at 5:32 pm

    RadBrad had the right idea, but the wrong implementation

    def price_check
      # Product Discount for Lavender Heart (Product code 001, greater than 2 in cart)        
      # Thought: Shouldn't you check to see if the name of the item is "Lavender Heart"?
      #          Checking if the product_id is 1 makes this test brittle
      if product_id == 1 && cart.items.quantity.count >= 2 
        discount_price
      else
        unit_price
      end 
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying something very simple, but for some reason it does not work.
I am trying to apply some transformations on images using a CGContextRef. I am
i am trying to apply some condition for an Auto generated textfield, the script
I'm trying to cut a xml into parts and then apply it some transformations.
I'm trying to simply draw some text with a stroke and then apply a
I'm trying to replicate some of the functionality in Apple's avTouch, but I can't
I'm trying to apply an xlst transformation using the following file. This is very
I am new to opengl programming, but I am doing something very basic, and
I am encountering a very weird issue. I am trying to apply global styling
I've been trying to add HTML content to a web view, but can't seem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.