加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 在Rails 4中发送一个带有远程true的表单

发布时间:2020-12-17 04:22:45 所属栏目:百科 来源:网络整理
导读:我有一个用于更新图像的表单 %= 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
我有一个用于更新图像的表单
<%= 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).我建议使用jqueryfileupload-rails gem和rails cast:

A. https://github.com/tors/jquery-fileupload-rails
B. http://railscasts.com/episodes/381-jquery-file-upload
> remote:true不是html属性.改变你的代码:

<%= form_for current_user,html: {multipart: :true},remote: true,:authenticity_token => true do |f| %>

您遇到的错误中最重要的部分是:

:formats=>[:html]

应该说:

:formats=>[:js]

使用remote:现在在正确的位置为true,错误应该消失.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读