var photo_token_inputs = [ "input[name='<%= j params[:page_part_id] %>[photo_collection_attributes][photo_tokens]']", "input[name='<%= j params[:page_part_id] %>[photo_tokens]']" ] var hidden_input = $(photo_token_inputs.join(", ")) <% if @photos.present? %> var photo_collection = $("<%= j render partial: 'photo_collection', locals: {photos: @photos} %>"); hidden_input.parents('.horizontal-form-content').find('.photo-collection').html(photo_collection); hidden_input.val("<%= @photos.map(&:id).join(',') %>"); <% else %> hidden_input.val(""); hidden_input.parents('.horizontal-form-content').find('.photo-collection').empty() <% end %> $('.sortable-grid').sortable().bind('sortupdate', function(e) { position_array = []; $(e.target).find('li.image').each(function(index) { position_array.push($(this).data('photo-id')); }); $(e.target).parents('.horizontal-form-content').find('.photo-positions').val(position_array.join(",")); }); $('.sortable-grid').trigger('sortupdate'); $.hideModal();