我有一个模型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
答案 0 :(得分:1)
您的资产表中似乎没有提交submission_id。
您必须生成资产模型,如:
rails generate model Asset submission_id:integer #rails 3
然后运行:
bundle exec rake db:migrate #rails 3