저는 Padrino를 사용하고 있으며 이미지가 많은 개체의 형태 안에 이미지 업로드 필드를 표시하려고합니다. project.rb
모델
class Project < ActiveRecord::Base
has_many :images, class_name: 'ProjectImage', foreign_key: 'project_id'
accepts_nested_attributes_for :images, allow_destroy: true
end
모델 project_image.rb
class ProjectImage < ActiveRecord::Base
belongs_to :project
mount_uploader :file, ProjectUploader
end
컨트롤러 projects.rb
get :new do
@title = pat(:new_title, :model => 'project')
@project = Project.new
@project.images.build
render 'projects/new'
end
부분 프로젝트 /_form.haml
= form_for :project, url(:projects, :create), multipart: true, :class => 'form-horizontal' do |f|
- f.fields_for :images do |image_f|
=image_f.label :file, :class => 'control-label'
.controls
=image_f.file_field :file, :class => 'form-control input-xlarge input-with-feedback', :multiple => true
그러나 중첩 된 image_f
필드는 표시되지 않습니다. 어떤 아이디어?
변화:
= form_for :project, url(:projects, :create), multipart: true, :class => 'form-horizontal' do |f|
...에
= form_for @project, url(:projects, :create), multipart: true, :class => 'form-horizontal' do |f|
대부분의 경우 당신은 또한 변화해야합니다 - f.fields_for
에= f.fields_for
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다