【问题标题】:Rails 3: Unknown attributeRails 3:未知属性
【发布时间】:2012-07-27 15:57:56
【问题描述】:

我想知道是否有人可以给我一些提示,说明为什么我在尝试创建我创建的模型(卡)的实例时遇到未知属性错误。这是模型类的精简版本和我收到错误的 rake 任务。

卡类:

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

【问题讨论】:

    标签: ruby ruby-on-rails-3 rake rake-task


    【解决方案1】:

    看来我遇到了另一个问题。我的数据库已经过时了。列名已从 type 更改为 card_type。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-13
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 2017-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多