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

  • SEARCH
  • Home
  • 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 9198797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:22:21+00:00 2026-06-17T22:22:21+00:00

I made a simple inventory system, and want to display a selector to choose

  • 0

I made a simple inventory system, and want to display a selector to choose the size before buying the product. I want the selector to only show the items that are in stock, and not allow the user to choose the ones that aren’t. I made it so that when the product is created, it creates a set of variants, with their name and quantity. So when I create a product, it creates 3 variants named Small, Medium, and Large, each with a qty of 0. I used the ruby console to update the qty of each variant so the below would work:

views/product/show.html.erb

<div class="size"><br/>Size: <%= f.select(:size, options_for_select(@sizes_availiable), :prompt => "Select a size") %></div>

product_controller.rb

  def show
    @product = Product.find(params[:id])
    @sizes_availiable = Product.build_size_enum( @product.id )
  end

Product.rd

  def self.build_size_enum(product_id)
    p = Product.find(product_id)
    a = []
    p.variants.each do |var|
      unless var.qty = 0
        a << var.name
      end
    end
    a
  end

However, the options are empty (with only the option “Select a size”). If I remove the unless statement (which defeats the purpose) from Product.rb so the method looks like below, the list populated with small medium and large:

Product.rd

  def self.build_size_enum(product_id)
    p = Product.find(product_id)
    a = []
    p.variants.each do |var|
      a << var.name
    end
    a
  end

Any ideas on why the unless statement is causing a problem?

  • 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-17T22:22:22+00:00Added an answer on June 17, 2026 at 10:22 pm

    You are using = instead of ==. var.qty = 0 will always test as “true” in Ruby, with the unfortunate side effect of wiping out the data you are trying to test. Change that to var.qty == 0 and you should be fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made simple email in wordpress but it would only send email to the
hi i've got question i've made simple form with attachment input and i want
I've made simple Qt4 design and I want to make it work with c++
I just made simple app using JodaTime libary. It does nothing special, only calculates
I made a simple gallery, using this script to show the images: $rs =
Made a simple script that hide/show a hidden div. The page automatically adjusts its
I made simple plugin and i would like to work this plugin only below
I've made simple nodejs application by using nodejs+express. Now I want to make user
I made a simple news system with comments using PHP and MySQL, and it
I made a simple graph to write MKV file. But I do not want

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.