【发布时间】:2018-11-22 13:20:08
【问题描述】:
我正在构建 Rails API。并使用 Postman 测试 API。通过 Postman 上传文件时,我没有在后端获取文件数组。尽管我得到了ActionDispatch::Http::UploadedFile 的类型。因此,我没有在post_params 中获得我的avatar。如何解决。
这是我的控制器类:
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
【问题讨论】:
标签: ruby-on-rails postman