0

这是prompt.rb

class Prompt < ActiveRecord::Base
  attr_accessible :title, :teacherUrl, :studentUrl, :image, :text;

  validates :title, :length => { :minimum => 5 };

  has_attached_file :image ;

  def initialize(params = nil)
    super(params)
    after_initialize
  end

  def after_initialize()
    self.teacherUrl = 'T' + (0...4).map{65.+(rand(26)).chr}.join ;
    self.studentUrl = 'S' + (0...4).map{65.+(rand(26)).chr}.join ;
  end
end

当我从 prompt_controller.rb (从默认的“新”方法)创建一个新的提示时,我得到:

undefined method `teacherUrl=' for #<Prompt:0x007fe3ac68adc0>

使用应用程序跟踪

app/models/prompt.rb:14:in `after_initialize'
app/models/prompt.rb:10:in `initialize'
app/controllers/prompts_controller.rb:43:in `new'
app/controllers/prompts_controller.rb:43:in `new'

这与 sqlite 完美配合。我刚刚将我的数据库切换到 Postgres,现在这个错误正在上升......似乎它无法相关,但这就是改变的全部(我可以返回一个修订版并且它再次完美运行)。

有什么问题?不是用 attr_accessible 定义的teacherUrl 吗?

4

1 回答 1

2

你需要做rake db:migrate。并且可能rake db:create(首先)。

于 2012-11-21T23:59:30.250 回答