Ruby Strong Params:NoMethodError整数的未定义方法许可证
我的控制器:Ruby Strong Params:NoMethodError整数的未定义方法许可证,ruby,strong-parameters,Ruby,Strong Parameters,我的控制器: class V1::SendContractController < V1::BaseController def create byebug bride_membership = Wedding.find(send_params[:weddingId]).bride_memberships[0] SendBrideContractJob.perform_now(bride_membership, send_params[:contractId]
class V1::SendContractController < V1::BaseController
def create
byebug
bride_membership = Wedding.find(send_params[:weddingId]).bride_memberships[0]
SendBrideContractJob.perform_now(bride_membership, send_params[:contractId])
render json: { enqueuedDelivery: true }, status: :ok
end
private
def send_params
params
.require(:weddingId)
.permit(:contractId)
end
end
错误
NoMethodError (undefined method `permit' for 4:Integer):
但是当我通过ebugit时,我得到了我想要的
(byebug) params
<ActionController::Parameters {"weddingId"=>4, "contractId"=>20, "controller"=>"v1/send_contract", "action"=>"create", "send_contract"=>{"weddingId"=>4, "contractId"=>20}} permitted: false>
(byebug) params[:weddingId]
4
我相信require会在您提供的密钥处为您提供对象,以便进行进一步的许可和/或请求调用
或许您可以尝试(未经测试):
编辑:这里也有:请参考此选项。require
确保存在一个参数。如果存在,则返回给定键处的参数,否则将引发ActionController::ParameterMissing错误
p={“weddingId”=>4,“constractd”=>20}
ActionController::Parameters.new(p).require(:weddingId)
# 4
p={“weddingId”=>nil,“constractd”=>20}
ActionController::Parameters.new(p).require(:weddingId)
#ActionController::ParameterMissing:param缺失或值为空:weddingId
如果要确保:weddingId
存在:
def合同参数
参数require(:weddingId)
参数许可证(:收缩,:婚礼ID)
结束
顺便说一句,SendContractController
最好称为ContractsController
(byebug) params
<ActionController::Parameters {"weddingId"=>4, "contractId"=>20, "controller"=>"v1/send_contract", "action"=>"create", "send_contract"=>{"weddingId"=>4, "contractId"=>20}} permitted: false>
(byebug) params[:weddingId]
4
axios.interceptors.request.use((config) => {
if(config.url !== "/authentications") {
config.paramsSerializer = params => {
// Qs is already included in the Axios package
return qs.stringify(params, {
arrayFormat: "brackets",
encode: false
});
};
axios.defaults.headers.common['Authorization'] = `Bearer ${store.state.token.token}`
config.headers.common['Authorization']= `Bearer ${store.state.token.token}`
axios.defaults.headers.common['Accept'] = 'application/vnd.bella.v1+json'
config.headers.common['Accept'] = 'application/vnd.bella.v1+json'
return config
}
return config
})
params.require(:weddingId)
params.permit(:weddingId, :contractId)