Ruby on rails RubyonRails控制器创建新参数

Ruby on rails RubyonRails控制器创建新参数,ruby-on-rails,ruby,Ruby On Rails,Ruby,在控制器中的创建方法中,我有: def create @monitoring_group = MonitoringGroup.new(monitoring_group_params) if @monitoring_group.save payload = { value: @monitoring_groups, status: 201 } render

在控制器中的创建方法中,我有:

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

当我运行create时,我得到了答案

> #<ActionController::ParameterMissing: param is missing or the value is empty: monitoring_groups>
>#

我对这个创建做了什么?

请求看起来像什么

该操作需要这样一个对象:

{
  "monitoring_groups": {
    "name":"Some name",
    "monitoring":[]
  }
}
是否正在添加外部监视组键


另请查看development.log->它将记录传入的请求。

您有
参数require(:监控组)
。这意味着params对象需要嵌套在
:monitoring_groups
键下的数据

如果请求来自HTML表单,则应该有如下内容:

监控组的
form_.new do| form|
...
结束

Hi,欢迎来到Stackoverflow。snippets功能用于可在浏览器中运行的HTML/CSS/JS前端示例。对于任何其他用于缩进空格或隔离代码块(`````)的代码,这仍然会给出
:监控组
而不是组。
{
  "monitoring_groups": {
    "name":"Some name",
    "monitoring":[]
  }
}