ruby on rails - Simple_form, edit multiple associated items -
i'm trying edit multiple association in single form. i'm using simple form , association easy:
class gallery has_many :pictures end class pictures end
every picture has image , caption, have uploaded pictures in separated form: need add caption text every picture in single form.
i try simple_form doing this:
= simple_form_for [:admin, gallery] |form| - if gallery.pictures.present? - gallery.pictures.each |p| = image_tag(p.image.url(:thumb), height: '50')
but cannot find way add caption text field every picture of gallery.
any hint?
use method simple_fields_for
nested resources
example:
simple_form_for [:admin, @gallery] |f| f.simple_fields_for :pictures |p| # here have simple_form methods available p.input :caption end end
also, add line gallery
class
#this allow save attributes on associated records through parent accepts_nested_attributes_for :pictures
update - show small thumb inside form each picture
image_tag(p.object.image.url(:thumb), height: '50')
Comments
Post a Comment