0

我有一个模型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

4

1 回答 1

1

似乎 submit_id 不存在于您的资产表中。

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

rails generate model Asset submission_id:integer #rails 3

然后运行:

bundle exec rake db:migrate #rails 3
于 2013-02-02T10:07:03.340 回答