问题标签 [remotipart]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
320 浏览

ruby-on-rails-3 - Rails Jquery使用remotipart gem NoMethodError上传文件:未定义的方法`name'

我正在使用 gem remotipart 上传文件。这是我的看法:

我的控制器:

但我收到此错误:NoMethodError: nil:NilClass 的未定义方法“名称”。我不知道方法名称来自哪里以及来自哪个类。任何帮助将非常感激。谢谢

0 投票
4 回答
884 浏览

remotipart - 使用 remotipart 插件上传图像时围绕 JS 的 Textarea

我正在使用 remotipart 插件进行 Ajax 图像上传。最近我将 Rails 版本从 3.1.10 升级到 3.2.13。升级 rails 版本后,我发现 ajax 图片上传不起作用。

我有使用 remotipart 插件提交图像并呈现响应的表单。但是在 rails 升级后我无法呈现响应。在调查这个问题时,我发现响应被 textarea 块包裹,因此没有被渲染。

我提到了一些相关的 stackoverflow 问题以及 remotipart 用户在 github 上报告的问题,但无法找出任何解决此问题的方法。

即: 当包含带有回形针的附件时,ajax 发布请求以 html 元素响应

Rails 3.2.8 的回形针和 Ajax 问题

https://github.com/JangoSteve/remotipart/issues/89

有人能建议我如何解决这个问题或我做错了什么吗?

谢谢并恭祝安康,

0 投票
1 回答
44 浏览

ruby-on-rails-3 - 如果在 Rails 3 中使用 Ajax,是否需要重新加载评论对象或包含评论的部分?

我一直在尝试在不使用 Ajax 重新加载页面的情况下添加评论,在阅读了几个不同的教程之后,这是我到目前为止所想到的,但它不起作用:

在 user_comments/_comments.html.erb 内

控制器内部:

在 create.js.erb 里面

我正在使用一个名为:remotipart的宝石

我不知道我在这个过程中缺少什么。在控制台中我得到:

这意味着帖子通过,但评论不会被添加回部分。

0 投票
0 回答
357 浏览

jquery - Upload file asynchronously using remotipart on drag and drop

I have my own implementation of text editor and would like to allow users to upload files by dragging and dropping it to the text editor. The editor uses iframe. I am using rails and remotipart to do async upload of image files. I tried using this plugin: http://chrismbarr.github.io/FileDrop/ but I can't figure out how to upload files using remotipart. I tried using AJAX but I am sure it is not the right way and moreover it does not work either:

Please comment if you need more code, the upload action or the html. I am using the following form to do async uploads of files using the remotipart gem and it works fine:

0 投票
1 回答
449 浏览

ruby-on-rails - Rails 4 - 带有remotipart的json.jbuilder

我的申请详情

  1. Rails 4.0 应用程序
  2. 遥控器gem remotipart (1.2.1)
  3. 使用 json.jbuilder 返回响应。
  4. 使用回形针 gem 上传文件paperclip (~> 4.1)

我有一个带有remote: trueand的表格multipart: true。提交表单后,我正在重新编写 json.jbuilder 模板。我ajax:success在表单上有回调。

当我提交没有附件的表单时,它会呈现 json.jbuilder 模板和 ajax:success回调工作。但是,如果我提交带有附件的表单,那么该表单将被提交呈现 json.jbuilder 文件。但是ajax:success回调不起作用。

自2天以来,我一直在努力解决这个问题。

提前致谢

0 投票
1 回答
459 浏览

jquery - Rails escape_javascript 和 remotipart

当用 jquery 和 rails(在 4.0.4 测试)替换 html 时,以下工作:

replace.js.erb 的内容

_my_partial.html.erb 的内容

但是,当使用 remotipart gem (1.2.1) 为响应 ajax 文件提交而呈现 replace.js.erb 时,它会失败,如下所示。

create.html.erb 的内容

它会在浏览器中导致以下 javascript 错误,因为引号未正确转义。

SyntaxError:意外的标识符

服务器响应:$('#my_div').html("\"This\" works\n"This" failed\n");

请注意,如果我在未选择文件的情况下提交,则不会发生 javascript 错误并且它会正确重新呈现。未选择文件时,似乎未调用 remotipart,可能是因为不需要多部分表单。

0 投票
1 回答
595 浏览

html - 使用 remotipart 提交带有文件输入的表单会包装一个文本区域以响应

使用 Ruby on Rails 4 和 Ruby 2。

这是我的简单控制器操作。当验证失败时,我会渲染“新”动作并将视图的内容注入到.ajax-targetdiv 中。



这种工作结构适用于每种类型的表单,除了具有文件输入类型且具有选定文件的表单。如果我提交所有字段为空白的表单,我会看到表单重新加载正常。如果我选择一个图像并将其他字段留空(以触发验证),我会得到:

“错误”文本,因为ajax:error响应。还可以在“网络”选项卡中查看:

0 投票
1 回答
1573 浏览

jquery - Rails 4 不使用 Remotipart 远程提交表单

看起来 Remotipart 实际上并没有用于提交我的表单,所以当我查看表单提交到的参数时,图像完全被忽略了。

remotipart_submitted?返回假

参数:{"utf8"=>"✓", "product"=>{"name"=>"RemotipartFails", "price"=>"10", "description"=>"Please work"}, "action"=>"create", "controller"=>"products"}

下面是更相关的代码

宝石

Javascript

形式

我没有尝试过,multipart: true因为我认为 form_for 会自动添加它,但这并没有帮助。

在这一点上,我对替代解决方案持开放态度(希望允许我远程提交带有图像的表单)

0 投票
0 回答
790 浏览

ruby-on-rails - 使用 Rails 4 异步上传文件

我有一个使用 rails jquery-UJS 异步提交的表单。只要没有文件输入,它就可以正常工作。当我添加文件输入时,表单停止异步提交,而是正常提交​​(整页重新加载)。

我发现由于浏览器不支持 ajax 文件,ajax:aborted:file如果表单中存在填充的文件输入,UJS 将触发该事件。 http://robots.thoughtbot.com/a-tour-of-rails-jquery-ujs

建议的解决方案是使用remotipart。https://github.com/JangoSteve/remotipart。然而,这个宝石自 2013 年以来就没有被触及过。我相信我在某处读到 Rails 4 包含此功能。

异步文件上传的 Rails 4 约定是什么?

0 投票
1 回答
4838 浏览

javascript - 使用远程表单上传 Ruby on Rails 文件:true

我正在尝试使用远程设置为 true 的 Rails 表单上传文件。我正在使用 Rails 4.1.1。假设我的模型是一个消息,它使用 JavaScript,以便用户可以轻松地发送多条消息而无需重新加载页面。表格设置如下:

用户可以上传带有消息的图像,如果他们愿意的话。MessageImage 在表单中充当嵌套属性,声明如下(http://railscasts.com/episodes/196-nested-model-form-revised方式):

在我的控制器上,动作大致是这样的:

现在,只要用户不发送任何图像,它就可以完美运行,但如果他们发送了,它会使用 format.html 而不是 format.js。删除 format.html 会给 ActionController::UnknownFormat-exception。

现在,这显然与您无法提交远程设置为 true 的文件有关。我试着搜索了一下,发现了这个宝石https://github.com/JangoSteve/remotipart,这似乎正是我正在寻找的。我按照说明安装了它,但由于某种原因,如果我删除 format.html,它仍然无法工作并给出 ActionController::UnknownFormat-exception。但是,我找不到任何涉及嵌套属性的示例。这个gem是否有任何替代方法或任何其他方法来解决这个问题,或者我应该设置它在用户提交文件时呈现HTML?