Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails “Rails活动记录”;论据太少”;创建/保存呼叫时_Ruby On Rails_Activerecord - Fatal编程技术网

Ruby on rails “Rails活动记录”;论据太少”;创建/保存呼叫时

Ruby on rails “Rails活动记录”;论据太少”;创建/保存呼叫时,ruby-on-rails,activerecord,Ruby On Rails,Activerecord,我的控制器中有一个相当简单的操作,如下所示: def create @quote = Quote.new(quote_params) if @quote.save render :json => @quote, :status => :created, :location => @quote else render :json => @quote.errors, :status

我的控制器中有一个相当简单的操作,如下所示:

def create
  @quote = Quote.new(quote_params)

  if @quote.save
    render :json => @quote,
           :status => :created,
           :location => @quote
  else
    render :json => @quote.errors,
           :status => :unprocessable_entity 
  end
end
我在我的应用程序的其他区域中也有同样的代码片段,这个问题不会发生

我正在用JSON向
/api/v1/quotes
发送一个POST请求,所有正确的参数都列在了白名单上

但是我得到了一个错误:
@quote.save
行上的参数太少了


这是为什么?

在quote_参数中发布您收到的内容。
params.require(:quote)。permit(:field1,:field2,:field3,:association_attributes=>[:id,:field1,:field2,:field3])
您已将代码放在上述注释中的“quote_参数”方法中。发布通过表单接收的参数。你可以在日志中查看。参数传递不正确,这就是它的给定参数错误的原因。这是我在
def quote_Params
end
中的注释是的,我知道。但这还不足以解决这个问题。您需要发布您通过表单获得的参数,以便它可以调试其给定参数错误的原因。发布您在quote_参数中收到的参数。require(:quote)。permit(:field1,:field2,:field3,:association_attributes=>[:id,:field1,:field2,:field3])
您已将代码放入上述注释中的“quote_params”方法中。发布通过表单接收的参数。你可以在日志中查看。参数传递不正确,这就是它的给定参数错误的原因。这是我在
def quote_Params
end
中的注释是的,我知道。但这还不足以解决这个问题。您需要发布您通过表单获得的参数,以便它可以调试其给定参数错误的原因。发布您在quote_参数中收到的参数。require(:quote)。permit(:field1,:field2,:field3,:association_attributes=>[:id,:field1,:field2,:field3])您已将代码放入上述注释中的“quote_params”方法中。发布通过表单接收的参数。你可以在日志中查看。参数传递不正确,这就是它的给定参数错误的原因。这是我在
def quote_Params
end
中的注释是的,我知道。但这还不足以解决这个问题。您需要发布通过表单获得的参数,以便它可以调试其给定参数错误的原因。