Rails 3.2我在"第一行收到错误:照片",它表示未定义的方法' model_name'符号:类。我迷失了这个。
= simple_form_for [@tower, :photos], remote: true, html: {class: 'form-horizontal'} do |f|
= f.error_notification
.modal-body
.modal-body-content
.form-inputs
- @photos.each_with_index do |photo, index|
= simple_fields_for photo do |p|
= render 'form_inputs', f: p, count: index
.modal-footer
= f.submit 'Save', class: 'btn btn-primary'
button.btn type="button" data-dismiss="modal" Cancel
_
# GET /towers/1/photos/new
def new
@tower = Tower.find(params[:tower_id])
@photos = Array.new(3){ @tower.photos.build }
respond_to do |format|
format.html # new.html.slim
format.json { render json: @photos }
end
end
同样在tower.rb" accepted_nested_attributes:photos"