错误指向
f.link_to_add
…线。当我去掉那条线,它就能正常工作了。但是我不能添加更多的图片。
<%= nested_form_for(:mark, url: place_mark_path, validate: true, html: {multipart: true}, 'data-update-target' => 'marks', class: 'marks') do |f| %>
...
<%= f.text_field :title %>
<%= f.check_box :mark %>
<%= f.fields_for :mark_images do |p| %>
<%= p.file_field :image %>
<%= p.link_to_remove %><br>
<% end %>
<%= f.link_to_add "+ Add another image", :mark_images %> <------ Problem
<%= f.submit " Submit" %>
<% end %>
路线
resources :places do
resources :marks
end
marks_controller
def new
query = @factual.table('places')
@place = query.filters('factual_id' => params[:place_id]).first
@mark = Mark.new
@mark.mark_images.build
end
标记模型
has_many :mark_images, :as => :attachable, :dependent => :destroy
accepts_nested_attributes_for :mark_images
mark_images模型 belongs_to :attachable, polymorphic: true
mount_uploader :image, ImageUploader
改变这一行
<%= nested_form_for(:mark, url: place_mark_path, validate: true, html: {multipart: true}, 'data-update-target' => 'marks', class: 'marks') do |f| %>
<%= nested_form_for(@mark, url: place_mark_path, validate: true, html: {multipart: true}, 'data-update-target' => 'marks', class: 'marks') do |f| %>