I am building Rails API. And using Postman to test the API. While uploading file through Postman I am not getting array of files in backend. In spite I am getting the type ActionDispatch::Http::UploadedFile
. Because of that I am not getting my avatar
in post_params
. How to fix it.
Here is my controller class:
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