Access to objects in semantic_fieds_for loop / formtastic

The model has accepts_nested_attributes_for for the relationship, and the form is as follows:

= semantic_form_for @obj, :url => path do |f|  
  =  f.inputs do
    = f.input :name
    = f.semantic_fields_for :photos do |p|
      = p.inputs :desc
  = f.buttons

The form works well and everything is in order. However, I would like to display each photo next to the field, so the user could imagine which photo she would comment on. In any case, to access photos.id inside the fields_for loop?

Edit:

Is there a way to change the display order of the photo fields in this example. As far as I can tell so far, this order is rather random.

+3
source share
1 answer

Well, that was easy enough, the object is accessible:

p.object

:-)

default_scope order(...)
+1

Source: https://habr.com/ru/post/1770483/


All Articles