Here is my code. if I write plural "param :asset_allocations, Array do" it doesn't work but if i write singular "param :asset_allocation, Array do" it works.
using Rails 5.0.2
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin15]
What I am missing?
module Api::V1
class FundsController < Api::V1::BaseController
before_action :authenticate_user!, except: []
def_param_group :asset_allocations do
param :asset_allocation, Array do
param :id, Integer, "POST doesn't require any value."
param :fund_id, Integer, "fund_id from Fund"
param :asset_class_id, Integer, "asset_class_id from AssetClass"
param :rate, Float
end
end
def_param_group :fund do
param :fund, Hash do
param :name, String, "Name of the fund"
param_group :asset_allocations
end
end
api :POST, '/v1/funds', 'Creates a fund.'
param_group :fund
def create
fund = Fund.new(fund_params)
auth_fund = authorize_with_permissions(fund)
if fund.save
render json: auth_fund.record,
serializer: Api::V1::FundSerializer,
status: 201
else
render json: fund.errors,
status: 406
end
end
private
def fund_params
fund_ps = params.require(:fund).permit(:name,
asset_allocations: [:id, :fund_id, :asset_class_id, :rate, :_destory])
fund_ps[:asset_allocations_attributes] = fund_ps.delete :asset_allocations
fund_ps.permit!
end
Here is my code. if I write plural "param :asset_allocations, Array do" it doesn't work but if i write singular "param :asset_allocation, Array do" it works.
using Rails 5.0.2 ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin15]
What I am missing?
module Api::V1 class FundsController < Api::V1::BaseController before_action :authenticate_user!, except: []
end end