لا يتم عرض حقول كائنات النموذج المتداخلة
سؤال
أنا أستخدم 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
مراقب مشاريع.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
لا تنتمي إلى StackOverflow