In create method in controller i have:
def create
@monitoring_group = MonitoringGroup.new(monitoring_group_params)
if @monitoring_group.save
payload = {
value: @monitoring_groups,
status: 201
}
render json: @monitoring_group, status: :created#, location: @monitoring_group
else
payload = {
error: "One or more monitorings do not belong to this account",
status: 400
}
render :json => payload, :status => :bad_request
end
end
And
def monitoring_group_params
params.require(:monitoring_groups).permit(:name, monitoring: [])
end
I have the answer when i run the create
> #<ActionController::ParameterMissing: param is missing or the value is empty: monitoring_groups>
What i do to this create ?
What does the request look like?
The action expects an object like so:
{
"monitoring_groups": {
"name":"Some name",
"monitoring":[]
}
}
Are you adding the outer monitoring_groups key?
Also look at the development.log -> it will log the incoming request.
You have params.require(:monitoring_groups)
. This means that the params object expects data nested under the :monitoring_groups
key.
If the request is coming from an HTML form, you should have something like this there:
form_for MonitoringGroup.new do |form|
...
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.