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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:09:01+00:00 2026-05-26T05:09:01+00:00

I have a simple rake task importing records from a CSV file and saving

  • 0

I have a simple rake task importing records from a CSV file and saving them into the database.

require 'csv'

namespace :import do
  task :items => :environment do

  CSV.foreach(Rails.root.to_s + '/public/data/items.csv', :headers => true) do |row|

   @item_id = row[1]

   if item_id
    i = Item.find_or_create_by_item_id(@item_id)
    i.update_attributes(
      :item_id     => @item_id,
      :category    => row[2],
      :price       => row[3],
    )
    i.save
   end

  end

 end
end

When I run it I get the following error.

rake aborted!
undefined method `save' for []:ActiveRecord::Relation

This was working fine and I have other rake tasks using dynamic finders on the same model in the same way which work fine. I can’t figure out what changed or what is causing this. Any ideas would be greatly appreciated.

  • 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-26T05:09:01+00:00Added an answer on May 26, 2026 at 5:09 am

    You have if item_id. Should that be @item_id? Also, update_attributes automatically saves the record. You don’t need to call save(). Remove that line and see if that gets rid of the error.

    As a side note, why do you have an attribute for Item called item_id? It would be a lot better just to use id unless you have a really good reason not to.

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

Sidebar

Related Questions

I have simple SSIS package which reads data from flat file and insert into
I have simple SSIS package where I import data from flat file into SQL
I'm working on a rake task which imports from a JSON feed into an
I am attempting to write a very simple rake task (and merge it into
I defined a simple rake task for running my ruby tests but have the
I have a simple rake task which consumes pretty much data via ActiveRecord. (contacts
I have been looking into Rake for build script in our CI system (Projects
In simple terms, what does Rake do? What purposes does it have? I understand
I have a couple simple rake tasks hosted at github that I would like
Ive got a simple Nunit runner for a rake script i have: module NUnitRunner

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.