我正在为我的Rails网站制作一个自定义编辑器,我需要使用AJAX将图像直接上传到我的编辑器中。我把所有东西都搞砸了,唯一的问题是在image_fields中,在fields_for里面,对于项目的form_for里面的部分没有包装在标签中。没有那些表单标签我的AJAX / Javascript不起作用
项目表格:
<%= form_for @project do |f| %>
<h1>New Project</h1>
<div class="field">
<%= f.label :title %>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :involvment, "Involvement" %>
<%= f.text_field :involvment %>
</div>
<div class="field">
<%= f.label :project_link, "Project Link" %>
<%= f.text_field :project_link %>
</div>
<div class="field">
<%= f.label :background, class: 'btn' do %>
Upload Image <i class="fa fa-upload" aria-hidden="true" style='margin-left: 20px'></i>
<% end %>
<%= f.attachment_field :background, direct: true, class: "hidden" %>
</div>
<%= f.fields_for :sections do |section| %>
<%= render "section_fields", f: section %>
<div class="links">
<%= link_to_add_association 'Add Section', f, :sections, class:"clickTarget" %>
</div>
<% end %>
<% end %>
section / section_fields的字段
<div class="nested-fields">
<div class="field">
<%= f.label :content %>
<div class="editor">
<div class="toolbar">
<div class="toolbarItem boldText">
<div class="button bold">
<i class="fa fa-bold" aria-hidden="true"></i>
</div>
</div>
<div class="toolbarItem italicText">
<div class="button italic">
<i class="fa fa-italic" aria-hidden="true"></i>
</div>
</div>
<div class="toolbarItem underlineText">
<div class="button underline">
<i class="fa fa-underline" aria-hidden="true"></i>
</div>
</div>
<div class="toolbarItem link">
<div class="button able-active link">
<i class="fa fa-link" aria-hidden="true"></i>
</div>
<div class="toolbarSettings link">
<label for="linkBox">Insert link URL</label>
<input type="text" class="linkBox"/>
<button class="finEditor">Insert Link</button>
</div>
</div>
<div class="toolbarItem image">
<div class="button able-active image">
<i class="fa fa-picture-o" aria-hidden="true"></i>
</div>
<div class="toolbarSettings link">
<%= render 'image_fields' %>
</div>
</div>
</div>
<%= f.text_area :content, class:"editorTextarea" %>
</div>
<%= link_to_remove_association "Remove Section", f, class:"clickTarget" %>
</div>
Image / Image_fields表格
<%= form_for @image, url: new_image_path, method: :post do |image| %>
<%= image.label :image, "Upload an Image" %>
<%= image.attachment_field :image, direct: true %>
<p>Or</p>
<%= image.label :remote_image_url, "Insert Image URL" %>
<%= image.text_field :remote_image_url, id: "linkBox" %>
<button class="finEditor">Insert Image</button>
<% end %>