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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:37:10+00:00 2026-06-02T06:37:10+00:00

I have a bit of code that checks if a user is in the

  • 0

I have a bit of code that checks if a user is in the "sakai_trained" array before proceeding. For some reason when I run this code:

CSV.foreach(activation_csv, {:headers => true}) do |row|
  if sakai_trained
    row << 'Untrained' unless sakai_trained.include?(row[1]) 
  end
  
  course_list << row
end

I get this error

C:/Ruby193/lib/ruby/1.9.1/csv.rb:478:in `==': undefined method `row' for "stuartademo":String (NoMethodError)
        from activate-courses.rb:42:in `include?'
        from activate-courses.rb:42:in `block in <main>'
        from C:/Ruby193/lib/ruby/1.9.1/csv.rb:1792:in `each'
        from C:/Ruby193/lib/ruby/1.9.1/csv.rb:1208:in `block in foreach'
        from C:/Ruby193/lib/ruby/1.9.1/csv.rb:1354:in `open'
        from C:/Ruby193/lib/ruby/1.9.1/csv.rb:1207:in `foreach'
        from activate-courses.rb:40:in `<main>'

I thought at first it was having a problem with the row[1] but it breaks the same way even with a string literal. I checked to make sure the sakai_trained array exists AND has data in it as well. I also tried rewriting it as an if statement in case the unless logic was flawed but that also returns the same error.

In case it’s unclear, I want to check that the userid located in row[1] exists in the sakai_trained array before adding the row to the course_list array. If it doesn’t, I want ‘Untrained’ added to the row first, then the row added to the array. When I removed the unless… part I was able to get a complete course_list array, but as expected, every row has "untrained". The problem appears to be with the

unless sakai_trained.include?(row[1])

part but I just can’t see it.

Update:

sakai_trained = []
  CSV.foreach(training_csv, {:headers => true}) do |trained|
    sakai_trained << trained
  end

Should I #map! each item with .to_s to make them into strings then?

Update 2:

I changed

sakai_trained << trained

to

sakai_trained << trained.to_s

and it’s removed the error, but the output still isn’t quite right.

Update 3:
ALMOST. WORKING. You guys are all incredibly awesome, and as frustrating as this is I have learned some new and interesting things.

Code:

course_list = []

if options[:verify]
  sakai_trained = []
  CSV.foreach(training_csv, {:headers => true}) do |trained|
    sakai_trained << trained.to_s
  end
end 
 
CSV.foreach(activation_csv, {:headers => true}) do |row|
  if sakai_trained && !sakai_trained.include?(row[1])  
    row << 'Untrained' 
  end
  
  course_list << row
end

Yields:

2124-5318,stuartademo,Untrained

2124-5320,bobsmith,Untrained

2124-4686,jimsmith,Untrained

2124-3560,jillsmith,Untrained

2124-3562,suesmith,Untrained

2124-5428,harrysmith,Untrained

When it should be

2124-5318,stuartademo,Untrained

2124-5320,bobsmith

2124-4686,jimsmith

2124-3560,jillsmith

2124-3562,suesmith

2124-5428,harrysmith

  • 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-02T06:37:11+00:00Added an answer on June 2, 2026 at 6:37 am

    The problem is occurring inside the csv.rb file in the standard Ruby library on line 478. Here’s the CSV code that is causing the problem for you:

    #
    # Returns +true+ if this row contains the same headers and fields in the
    # same order as +other+.
    #
    def ==(other)
      @row == other.row
    end
    

    From the looks of your error message, the String "stuartademo" is being passed into this method and, of course, there is no String#row. It looks like other should be a row of a csv file. According to the comments on the above method, it should contain headers and fields.

    I would suggest finding where this String "stuartademo" is coming from and figure out why only the String is getting passed in instead of the entire row.

    EDIT:

    If sakai_trained is populated from a CSV, then it is not an array but rather CSV:Row type. In this case, when you call CSV::Row#include? then the ==(other) is getting called. Hence, what you are passing into is, row[1] is a String. It should not be a String.

    Instead of using include?, try using field?(data) or fields.include?.

    CSV.foreach(activation_csv, {:headers => true}) do |row|
      if sakai_trained
        row << 'Untrained' unless sakai_trained.field?(row[1]) 
      end
    
      course_list << row
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bit of code that looks like this: text = reg.Replace(text, new
Well, I have this bit of code that is slowing down the program hugely
I have the following bit of code that worked as expected before we upgraded
Ok. I have this little bit of code that is supposed to use text
I have a bit of code that checks a list if LI tags which
i have bit of code that causes an underflow: var t1, t2, delta: DWORD:
I have a bit of code that basically reads an XML document using the
I have a bit of code that passes around a ton of objects and
I have a bit of Javascript code that creates a save friendly version of
I have the following bit of code that is timing out when I pass

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.