2012-07-27 84 views
0

我想知道如果有人能够给我一些提示,说明为什么当我尝试创建我创建的模型(卡)的模型实例时,我得到未知属性错误。这里是模型类的剥离版本和rake任务,我收到错误。Rails 3:未知属性

卡类:

class Card < ActiveRecord::Base 
    has_and_belongs_to_many :some_other_model 
    belongs_to :some_other_other_model 
    attr_accessible :attr1, :attr2, :attr3, :attr4,...,:card_type,... 
end 

耙子任务:

task :import_cards => :environment do 
    # connect to database 
    conn = Mysql2::Client.new(yadda yadda yadda) 

    results = conn.query("SELECT attr1, attr2, attr3, attr4,..., card_type, ... FROM that_table;") 

    results.each{|row|; Card.create(:attr1 => row['attr1'], :attr2 => row['attr2'], :attr3 => row['attr3'], :attr4 => row['attr4'],..., :card_type => row['card_type'],...);} 

    conn.close() 
end 

回答

0

看起来像我的另一个问题。我的数据库已过时。列名已从类型更改为card_type。