Hello, I have the next:
class Post < ActiveRecord::Base has_many :image, :dependent => :destroy accepts_nested_attributes_for :image, :allow_destroy => true, :limit => 4 end
class Image < ActiveRecord::Base belongs_to :Post ... paperclip settings ... end
And the form view for the post is:
<%= nested_form_for @post, :html => { :multipart => true } do |f| %> <%= f.fields_for :images do |i| %> <% if i.object.new_record? %> <%= i.file_field :photo %> <% else %> <%= image_tag(i.object.photo.url(:thumb)) %> <% end %> <%= i.link_to_remove "Remove this image" %> <% end %> <%= f.link_to_add "Add a Image", :images %> <%= f.submit %> <% end %>
The problem is when I add more images that the limit. Although I delete it before submit the form, the post don't validate: ActiveRecord::NestedAttributes::TooManyRecords. For example, if I may have 2 limit image and I do: - Add Image - Add Image - Add Image - Delete Image - Delete Image - Browse Image File - SUBMIT FORM
Well, I would get the error. It's a bug? Any help? Thanks