2013-03-22 3 views
0

레일스에 주가 기록에 대한 모델이 있습니다.이 데이터를 야후 파이낸싱 API에서 내 모델로 대량 가져 오기하고 싶습니다.정의되지 않은 메소드 each_with_index activerecord-import

이 내가 가진 무엇 :

말하는 오류가 발생
columns = [:date,:open,:high,:low,:close,:volume,:adjusted_close,:asset_symbol] 
values = ['2013-03-22',1,2,3,4,5,6,'YHOO'] 

AssetHistory.import columns,values 

: 내 값 배열의 날짜가 내 모델에서 실제로 종류의 일이다 undefined method each_with_index for '2013-03-22':String from .../activerecord-import/import.rb

하는 것으로. (그게 문제니까?)

Active Record-Import 0.3.1 및 Rails 3.2를 사용하고 있습니다. 또한 중요한 경우 Postgresql을 사용하고 있습니다. 주석과

내 자산 역사 모델 :

# Table name: asset_histories 
# 
# id    :integer   not null, primary key 
# date   :date 
# open   :float 
# high   :float 
# low   :float 
# close   :float 
# volume   :integer 
# adjusted_close :float 
# asset_symbol :string(255) 
# asset_id  :integer 
# 

class AssetHistory < ActiveRecord::Base 
    attr_accessible :adjusted_close, :close, :date, :high, :low, :open, :volume, :asset_id, :asset_symbol 
    has_and_belongs_to_many :assets 
    validates_uniqueness_of :asset_symbol, scope: [:date] 
end 

이 문제가 무엇인지 어떤 이유?

답변

1

개체를 모델로 가져 오는 동안 다음과 같이 메서드를 호출해야합니다. 예를 들어

Model.import <array_of_cols>, <array_of_values> 

: 위의 예는 샘플 모델의 두 개의 레코드를 생성합니다

Sample.import [:field1, :field2], [["value-a1", "value-a2"], ["value-b1", "value-b2"]] 

.

그래서 귀하의 경우 다음과 같이 제공하십시오.

AssetHistory.import columns, [values] 

희망.

관련 문제