Rails 3嵌套模型中的未知属性错误

时间:2013-02-01 22:49:24

标签: ruby-on-rails

我有一个模型submission和一个嵌套模型attachment

submission.rb中的

has_many :assets, :dependent => :destroy
accepts_nested_attributes_for :assets, :allow_destroy => true
assets.rb中的

  attr_accessible :file_id, :attachment
  belongs_to :submission
  has_attached_file :attachment

在我的submission控制器中:

def new
    @submission = Submission.new
    @asset = 2.times{ @submission.assets.build }

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @submission }
    end
  end

  def edit
    @submission = Submission.find(params[:id])
    @asset = 2.times{ @submission.assets.build }
  end

我收到unknown attribute: submission_id错误。

这里可能有什么问题。

我正在关注截屏视频: http://www.emersonlackey.com/article/rails-paperclip-multiple-file-uploads

1 个答案:

答案 0 :(得分:1)

您的资产表中似乎没有提交submission_id。

您必须生成资产模型,如:

rails generate model Asset submission_id:integer #rails 3

然后运行:

bundle exec rake db:migrate #rails 3