Rails wrap

编程入门 行业动态 更新时间:2024-10-28 10:25:22
本文介绍了Rails wrap_parameter无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用AngularJS和jQuery-file-uploader插件.我已经配置了rails来包装我的参数

I'm working with AngularJS and the jQuery-file-uploader plugin. I've configured rails to wrap my parameters with

ActiveSupport.on_load(:action_controller) do wrap_parameters format: [:json] end

这一切都可以正常工作,除非我尝试上传文件.我使用的上载器插件与正常使用略有不同,但它仍可以正常工作.而是让插件在添加文件时上传文件,我创建一个新记录,然后上传文件.该请求已正确触发,但是文件的参数没有被rails包裹.在我的日志中,我得到了

This is working fine for everything except when I try and upload my files. I'm using the uploader plugin slightly differently to normal but it should still be working. Rather the letting the plugin upload files when they're added, I'm creating a new record, and THEN uploading the files. The request is firing correctly, however the parameter(s) for the file(s) is/aren't being wrapped by rails. In my logs I am getting

Processing by MeetingsController#update as JSON Parameters: {"icon"=>#<ActionDispatch::Http::UploadedFile:0x007fde79178b58 @original_filename="006.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"icon\"; filename=\"006.png\"\r\nContent-Type: image/png\r\n", @tempfile=#<File:/var/folders/_v/qsm9g7nn00s0jmfkynmvwp140000gn/T/RackMultipart20130505-15753-17ig2it>>, "id"=>"35"}

我希望看到参数

{ :meeting => { :icon => ... }}

在我的MeetingsController中,我已经

wrap_parameters :meeting, include: [..., :icon, ...]

同样通过此控制器进行的记录创建工作完美,并且参数按预期进行了包装,但是不适用于此记录.我在做错什么吗?

The record creation which also goes through this controller works perfect, and the parameters are being wrapped as expected, however it won't work for this. Am I doing something wrong?

推荐答案

这是因为文件上传请求具有multipart/form-data格式.

That's because the file upload request has the multipart/form-data format.

要也以这种格式激活自动包装,您可以添加format选项:

To activate the autowrappring too in this format, you can add the format option :

class MeetingsController < ApplicationController wrap_parameters :meeting, include: [..., :icon, ...], format: [:json, :multipart_form] ... end

更多推荐

Rails wrap

本文发布于:2023-10-21 17:43:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1514922.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Rails   wrap

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!