Ruby on rails ActionController::ParameterMissing(param缺失或值为空:account)

Ruby on rails ActionController::ParameterMissing(param缺失或值为空:account),ruby-on-rails,Ruby On Rails,大师, 需要RoR API的帮助吗 我看到所有必需的参数都已发送,但服务器不喜欢其中一个或部分参数 控制器: def创建 @account=account.newaccount\u参数 if @account.save render json: @account, status: :created, location: @account else render json: @account.errors, status: :unprocessable_entity end 结束 这个电

大师, 需要RoR API的帮助吗 我看到所有必需的参数都已发送,但服务器不喜欢其中一个或部分参数

控制器: def创建 @account=account.newaccount\u参数

if @account.save
  render json: @account, status: :created, location: @account
else
  render json: @account.errors, status: :unprocessable_entity
end
结束

这个电话是这样的: 于2020-11-27 01:16:08-0700开始记账/账户?名称=TD交易和货币id=1和机构=TD%20Waterhouse&类型=投资和客户id=1 for::1 按AccountsController处理创建为/ 参数:{name=>TD-Trading,currency\u-id=>1,institution=>TD-Waterhouse,type=>Investment,client\u-id=>1} 客户端加载0.4ms选择客户端。*从客户端,其中clients.email=$1 ORDER BY clients.id ASC LIMIT$2[[email,akaghzi@gmail.com],[限制,1]] 在271ms ActiveRecord中完成了400个错误请求:0.4ms |分配:1706

ActionController::ParameterMissing param缺失或值为空:帐户:

app/controllers/accounts\u controller.rb:55:in account\u params'app/controllers/accounts\u controller.rb:21:in create'

这段代码:

def帐户参数 参数require:account.permit:client_id、:currency_id、:name、:type、:institution 终止 表示它需要一个包含属性的帐户哈希。您的日志显示您发送了未包装在帐户哈希中的所有属性。 您可以通过将参数包装在帐户散列中或从帐户参数中删除require:account部分来解决此问题。

这段代码:

def帐户参数 参数require:account.permit:client_id、:currency_id、:name、:type、:institution 终止 表示它需要一个包含属性的帐户哈希。您的日志显示您发送了未包装在帐户哈希中的所有属性。
您可以通过将参数包装在帐户散列中或从帐户参数中删除require:account部分来解决此问题。

模型出现问题,我将列命名为type,现在我已将account类型更改为,但是,行为是一样的。我已经使用rails控制台测试了这些值,它可以工作:account=account.newname:'TD Trading',institution:'TD Waterhouse',account_type:'Investment',currency_id:1,client_id:1 account.valid?=>True模型中有一个问题,我将列命名为类型,我现在已将其更改为帐户类型,但行为是相同的。我使用rails控制台测试了这些值,结果是:account=account.newname:'TD Trading',institution:'TD Waterhouse',account\u type:'Investment',currency\u id:1,client\u id:1 account.valid?=>非常感谢,我使用postman测试api并使用参数,但是当我使用body发送数据时,它解决了问题。因此,当postman以哈希形式发送数据时,它收到了适当的响应,再次感谢您的解释。非常感谢,我使用postman测试api并使用参数,但是当我使用body发送数据时,它解决了问题。因此,邮递员在将数据作为哈希发送时收到了相应的响应,再次感谢您的解释。
def account_params
  params.require(:account).permit(:client_id, :currency_id, :name, :type, :institution)
end