<% content_for :javascript_includes do %> <%= javascript_include_tag "/assets/ckeditor/ckeditor" %> <% end %> <%= simple_form_for [:admin, @product], wrapper: :horizontal_form, wrapper_mappings: { check_boxes: :horizontal_collection, file: :horizontal_file } do |f| %> <%= f.error_notification %> <%= f.input :category_id, collection: @categories %> <%= f.input :name %> <%= f.input :price %> <%#= f.input :compatibility, :as => :hidden %> <%= f.input :compatibility, collection: @compatibility, as: :check_boxes, label: "Compatibility", input_html: { multiple: true} %> <% index = 0%> <%= f.simple_fields_for :product_images do |p| %> <% if p.object.new_record? %> <%= p.input :image, as: :file, input_html: { multiple: true, name: "product[product_images_attributes][][image]" } %> <% else%> <% if index == 0%>
<%= link_to "Add New Image", new_admin_product_image_path(@product.id), class: "btn btn-success", remote: true %>
<% end %> <% index +=1 %>
<%= image_tag p.object.image.url(:thumb), class: "img-fluid" %>
<%= link_to "edit", edit_admin_product_image_path(@product.id, p.object.id), class: "btn btn-primary mb-2", remote: true %> <%= link_to "delete", admin_product_image_path(@product.id, p.object.id), class: "btn btn-danger mb-2", :method => :delete, data: {:confirm => "Are you sure?"} %> <% if !p.object.is_primary %> <%= link_to "Set As Primary", set_as_primary_admin_product_path(@product.id, p.object.id), class: "btn btn-primary mb-2" %> <% end %>
<% if index == f.object.product_images.size.to_i %>
<% end %> <% end %> <% end %> <%= f.input :short_description, as: :text, :input_html => {:rows => 7} %> <%#= f.input :description, as: :ckeditor, input_html: { ckeditor: { toolbar: 'Full' } } %> <%= f.input :specification, as: :text, :input_html => {:rows => 7} %> <%= f.input :feature, as: :text, :input_html => {:rows => 7} %> <%= f.input :page, :as => :hidden, :input_html => { :value => params[:page] || 1 } %>
<%= f.button :submit, class: "btn-primary" %> <%= link_to "Cancel", admin_products_path(:page => params[:page]), class: "btn btn-outline-secondary" %>
<% end %>