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 8813409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:50:35+00:00 2026-06-14T03:50:35+00:00

An Item has_many Pieces . I have two methods, one that finds out if

  • 0

An Item has_many Pieces. I have two methods, one that finds out if the Piece is available and one that finds out if an Item has available pieces.

  # in piece.rb
  def available?(current_user, piece)
    if piece.status == 1
      true
    elsif piece.status == 2
      false
    elsif piece.status == 3
      true if piece.friend_id == current_user.id
    end
  end

  #in item.rb
  def available?(current_user, user, item)
    false
      item.pieces.each do |piece|
        if piece.available?(current_user, piece)
          true
        end
      end
  end

My available? method in Item is wrong. I want it to return true if an Item has available pieces, and false if not. Theory behind my code is that the method returns false unless there is a piece that returns true. When I do it in the console all I get are the pieces in a hash, not true or false.

Can anyone solve my problem or tell me a better way to do this?

  • 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-14T03:50:36+00:00Added an answer on June 14, 2026 at 3:50 am

    If you need to check whether item has at least one available piece, the method can look like this:

    def available?(current_user, user, item)
      item.pieces.each do |piece|
        return true if piece.available?(current_user, piece)
      end
      false
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My ListView item has two TextViews. I want to show one of them at
I have a list view that displays a collection of items, each item has
I have a class, Item that has many Rates . They are keyed by
I have model represent association rule (Body => Head) def Item has_many :heads has_many
I have a Location that has_many Item class. items have a scope for is_enabled.
I have an object, that has many properties but the only two to worry
Let's say that I'm looking for a specific item in a has_many association. Is
My model: class User has_many :items end class Item belongs_to :user def self.with_color(color, is_loaded)
I have a listview and each item has a title, some info, and a
I have a simple FAQ page in which each item has the following HTML

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.