生徒のコース課題に添付された複数のファイルをクリップを使用してアップロードしましたが、失敗します。
モデル
class StudentCourseAssignment < ActiveRecord::Base
attr_accessible :score, :comment, :finish_status,:attachments
accepts_nested_attributes_for :attachments
belongs_to :assignment
belongs_to :user
has_many :attachments ,:as => :attachmentable,:dependent => :destroy
end
class Attachment < ActiveRecord::Base
attr_accessible :user_upload
belongs_to :attachmentable , :polymorphic => true
has_attached_file :user_upload
end
コントローラ
**new**
@sca = StudentCourseAssignment.new
@sca.attachments.build
@sca.attachments.build
**create**
@sca = StudentCourseAssignment.new(params[:student_course_assignment])
@assignment = Assignment.find(params[:assignment_id])
@sca.user = current_user
@sca.assignment = @assignment
if @sca.save
flash[:alert] = "success"
redirect_to course_years_path
else
flash[:alert] = "fail"
redirect_to course_years_path
end
** 見る**
<%= form_for @sca, :url => assignment_student_course_assignments_path(@assignment),
:html => { :id => 'student-assignment-form', :multipart => true } do |f| %>
file:
<%= f.fields_for :attachments do |a_f| %>
<%= a_f.file_field :user_upload %>
<%= submit_tag "create" %>
<% end%>
<% end %>
違う
No association found for name `attachments'. Has it been defined yet?
accept_nested_attributes_for :attachments を削除しても、まだ間違っています
Attachment(#70201401779680) expected, got Array(#70201383294620)
あなたの助けを願っています!thx!