当调用我的API端点时,我得到了以下错误:
ActiveModel::ForbiddenAttributesError (ActiveModel::ForbiddenAttributesError):
day_points_api.rb
module V1
class DayPointsApi < Grape::API
namespace 'api/v1' do
resource :points do
desc 'start all metrik jobs'
params do
requires :product, type: String
requires :type, type: String
requires :value_at, type: Date
requires :points, type: Array do
requires :platform, type: String
requires :country, type: String
requires :value, type: Float
end
end
post do
params[:points].each do |point|
point_params = point.merge(params.except(:points))
DayPoint.constantize.import(point_params)
end
end
end
end
end
end显然,这要归功于StrongParameter --但老实说,我已经定义了所需的参数--这些应该是默认允许的唯一参数。
有一些可用的使用辅助方法解决方案--我发现这些解决方案很难看。
这怎麽可能?还有其他选择吗?
https://stackoverflow.com/questions/32884569
复制相似问题