= form_for [:admin, @product], class: "col-lg-8" do |f| - if @product.errors.any? %div.alert.alert-danger.alert-block %h4 Продукт не сохранен из-за #{Russian.pluralize @product.errors.count, "ошибки", "ошибок", "ошибок", "ошибки"} %ul - @product.errors.full_messages.each do |msg| %li #{msg} %fieldset .form-group = f.label :title = f.text_field :title, class: 'form-control' .form-group = f.label :code = f.text_field :code, class: 'form-control' .form-group = f.label :manufacturer_id = f.collection_select :manufacturer_id, Manufacturer.readable_collection, :id, :title, {include_blank: true}, { class: 'form-control' } .form-group = f.label :catalogue_category_id = f.collection_select :catalogue_category_id, format_select_options(CatalogueCategory.readable_collection), :id, :title, {include_blank: true}, { class: 'form-control' } .checkbox = f.label :published, 'Опубликовать на сайте' = f.check_box :published .form-group = f.label :body = f.text_area :body, class: 'form-control redactorjs' .form-group = f.label :specifications = f.text_area :specifications, class: 'form-control redactorjs' .form-group = f.label :main_image_uri = f.file_field :main_image_uri = f.hidden_field :main_image_uri_cache = image_tag(f.object.main_image_uri, class: "img-responsive") if f.object.main_image_uri? %h3 Дополнительные изображения %div = f.fields_for :product_images do |product_image| = render 'product_image_fields', :f => product_image %div = link_to_add_association 'Добавить изображение', f, :product_images, class: 'btn btn-info' %h3 Документы %div = f.fields_for :product_documents do |product_document| = render 'product_document_fields', :f => product_document %div = link_to_add_association 'Добавить документ', f, :product_documents, class: 'btn btn-info' %h3 Связанные продукты #related_products = f.fields_for :related_products do |related_product| = render 'related_product_fields', :f => related_product %div = link_to_add_association 'Добавить связанный продукт', f, :related_products, class: 'btn btn-info' :javascript var typeahedFunction = function(nestedFieldsElement) { var titleInput = nestedFieldsElement.find(".typeahead > input[type='text']"); var idInput = nestedFieldsElement.find(".typeahead > input[type='hidden']"); titleInput.typeahead({ // name: 'products???', remote: '#{typeahead_get_data_admin_products_path}?q=%QUERY', minLength: 3, valueKey: 'title' }); titleInput.on("typeahead:selected typeahead:autocompleted", function(event, datum) { idInput.val(datum.id); }); }; $(document).ready(function() { var relatedProductsElement = $('#related_products'); relatedProductsElement.on('cocoon:after-insert', function(event, added) { // added -> nested_fields typeahedFunction(added); }); relatedProductsElement.find('.nested-fields').each(function(index, element) { typeahedFunction($(element)); }); }); %br %p =f.submit submit_button_text, :class => 'btn btn-default' %a.btn.btn-danger{:href => admin_products_path} Отменить