如何使用 Ruby 将另一个字段的值添加到 HTTParty 字段

How to add the value of another field to an HTTParty field using Ruby

可以这样使用:将密码生成的faker内容添加到“passoword_confirmation”。如果是这样,语法是什么,尝试各种方法都失败了!。谢谢

"email": Faker::Internet.email, "password": Faker::number(6), "password_confirmation":

@@base_url  = 'https://api-de-tarefas.herokuapp.com/users'
    @@body = 
    {
    "user": {
    "email": Faker::Internet.email,
    "password": Faker::number(6),
    "password_confirmation":      here I want to receive the password generated from Faker.

     }    
}.to_json

您可以通过在进入 @@body 块之前将密码保存到变量来保留密码。

@@base_url  = 'https://api-de-tarefas.herokuapp.com/users'
fake_password = Faker::number(6)
@@body = 
{
  "user": {
    "email": Faker::Internet.email,
    "password": fake_password,
    "password_confirmation": fake_password

   }    
}.to_json