我有一个用于更新图像的表格
<%= form_for current_user, url: update_image_user_path(current_user), method: :post, html: {multipart: :true, remote: true}, :authenticity_token => true do |f| %>
该行动有
respond_to do |format|
format.js
format.html
end
但我收到以下错误
ActionView::MissingTemplate - Missing template users/update_image, application/update_image with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :coffee]}.
我没有 update_image.html.erb 模板,但从错误中我了解到请求不是以 js 格式发送的
我缺少什么?
有几件事你应该知道。
-
Ajax 使用称为 xmlhttprequest 的东西来发送数据。不幸的是,xmlhttprequests 无法发布文件。 Remotipart 可能有效,但 jqueryfileupload 上有更多文档,以及 Rails Cast 视频。许多站点都使用它(很多站点甚至不使用 Rails)。我建议将 jqueryfileupload-rails gem 与 Rails 演员一起使用:
A. https://github.com/tors/jquery-fileupload-rails https://github.com/tors/jquery-fileupload-rails
B. http://railscasts.com/episodes/381-jquery-file-upload http://railscasts.com/episodes/381-jquery-file-upload
-
remote: true 不是 html 属性。更改您的代码:
<%= form_for current_user, url: update_image_user_path(current_user),
method: :post, html: {multipart: :true}, remote: true,
:authenticity_token => true do |f| %>
您遇到的错误最重要的部分是:
:formats=>[:html]
那应该说:
:formats=>[:js]
现在,remote:true 位于正确的位置,错误应该会消失。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)