Ruby on rails ActionDispatch::Http::将文件上载到活动存储Rails 5.2的阵列

Ruby on rails ActionDispatch::Http::将文件上载到活动存储Rails 5.2的阵列,ruby-on-rails,postman,Ruby On Rails,Postman,我正在构建Rails API。并使用Postman测试API。通过邮递员上传文件时,我并没有在后端获得文件数组。尽管我得到了类型ActionDispatch::Http::UploadedFile。因此,我无法在post_params中获得我的化身。如何修复它 这是我的控制器类: class Api::V1::PostsController < Api::V1::BaseController skip_before_action :authenticate, only: [:creat

我正在构建Rails API。并使用Postman测试API。通过邮递员上传文件时,我并没有在后端获得文件数组。尽管我得到了类型
ActionDispatch::Http::UploadedFile
。因此,我无法在
post_params
中获得我的
化身。如何修复它

这是我的控制器类:

class Api::V1::PostsController < Api::V1::BaseController
  skip_before_action :authenticate, only: [:create]
  before_action :current_timeline, only: [:create]

  def create
    post = current_timeline.posts.build(post_params)
    binding.pry
    if post.save
      render_success(:created, post, meta: {message: 'Post sucessfully added'})
    else
      render_error(421, post.errors)
    end

  end

  private

  def post_params
    params.require(:post).permit(:message, :user_id, :occasion_id, :timeline_id, avatars: [])
  end

  def current_timeline
    Timeline.find(post_params[:timeline_id])
  end
end
class Api::V1::PostsController
尽管我得到了类型
ActionDispatch::Http::UploadedFile

在postman中,您需要将字段名更改为
avatars[]
,然后您可以将avatars作为数组:

{"avatars"=>[#ActionDispatch::Http::UploadedFile....]}
您可以发送
avatars[]
param,带/不带括号中的索引,具体如下: