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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:23:25+00:00 2026-05-27T13:23:25+00:00

For some reason, the when @orgs is not working : @orgs = Organization.all.select{|a|a.active}.count case

  • 0

For some reason, the when @orgs is not working :

  @orgs = Organization.all.select{|a|a.active}.count
  case collection.size
  when 0; "No #{entry_name.pluralize} found"
  when @orgs; "#{@orgs} Businesses Returned!"
  else; "#{collection.total_entries} of #{@orgs} Businesses Returned!"
  end

Is this syntactically accurate? It will always return the last else statement. It never catches on the second when statement, even if @orgs == @orgs.

The actual number of @orgs = 1211.

So if I make the when statement when 1211; , it still doesn’t catch. Is there a syntactical mistake here?

  • 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-05-27T13:23:25+00:00Added an answer on May 27, 2026 at 1:23 pm

    Your syntax isn’t the issue. The logic in your conditions, I think, is all messed up.

    So, @orgs does not = 1211, @orgs is a collection whose size is 1211. Big difference.

    • This case statement will always fail because the case is collection.size, when it should probably be @orgs.size

    Let’s say we changed it to be:

    case @orgs.size
      ...
    

    Then:

    • Your first when statement would start working when @orgs.size == 0
    • Your second when statement would still fail, because @orgs.size != @orgs – and it never will. @orgs refers to the collection of objects, while @orgs.size refers to the size of that collection. Even when @orgs == nil it will still fail because @orgs.size will throw a error because you’re calling the size method on a nil object, which isn’t allowed.
    • Your else statement is always the one called because of the problems listed above, and because the way you’ve written it prevent any of the other cases from ever being true.

    However, that’s probably still not enough. It looks to me like you’re trying to return singularized or pluralized text depending on how many you have. Here’s the code you probably intended to write, without the semi-colon usage:

    @active_orgs = Organization.all.select{|a| a.active}
    @singular_name = Organization.class.name
    @plural_name = @singular_form.pluralize
    
    case @active_orgs.size
    when 1
      "1 active #{@singular_name} of a total #{Organization.count} #{@plural_name}!"
    else
      "#{@active_orgs.count} active #{@singular_name} of a total #{Organization.count} #{@plural_name}!"
    end
    

    This will pluralize even when the count is 0, so it will say 0 active Organizations of a total 125 Organizations!

    … or when the value is 1 it will say 1 active Organization of a total 125 Organziations!

    If you don’t want Organization capitalized, you can add a call to .downcase to take care of that.

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

Sidebar

Related Questions

For some reason I am not able to access procNames.count. All I need to
For some reason this is not working. Instead it thinks it should check the
For some reason, this works in all major browsers, but not IE (surprise, surprise).
For some reason the toggleClass function does not seem to be working. I have
For some reason I never see this done. Is there a reason why not?
For some reason, Section 1 works but Section 2 does not. When run in
For some reason my simple jquery bind event isn't working. The funny thing is
for some reason my event data isn't working correctly with jquery fullcalendar when I
For some reason, my code displays correctly in all browsers except IE8. <form dojoType=dijit.form>'
Theres some reason for this code not reach the first else? I got it

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.