ruby - 是否可以在一个字段中接收从 Faker 生成的另一个字段的值?
问题描述
@@base_url = 'https://api-de-tarefas.herokuapp.com/users'
@@body =
{
"user": {
"email": Faker::Internet.email,
"password": Faker::Number.number(6),
"password_confirmation":
}
}.to_json
我正在尝试将 gem faker 在密码字段中生成的值传递给密码验证字段。
解决方案
只需预先确定值:
@@base_url = 'https://api-de-tarefas.herokuapp.com/users'
password = Faker::Number.number(6)
@@body = {
"user": {
"email": Faker::Internet.email,
"password": password,
"password_confirmation": password
}
}.to_json
顺便说一句,您真的需要类变量(以 开头@@
)吗?我想不出类变量是一种好方法的许多情况。
推荐阅读
- amazon-web-services - Power BI 刷新超时
- java - 如果我的应用程序是使用 gradle 创建的,如何设置 mainClassName?
- objective-c - 编译器如何知道我想使用哪个函数?
- r - 如何使面板在 r markdown/runtime 闪亮中显示/隐藏反应数据表?
- android - 扫描 QR 码时,并非所有域都在 Android 上被解释为链接
- javascript - 如何在猫鼬中查询服务器的启动?
- python - 如何在不关闭连接的情况下获取整个消息 - 导致可能获取多条消息?
- c++ - 我正在尝试使用 STL 堆栈执行 DFS,但它给出了意想不到的结果
- excel - VBA Excel - 将相同的值添加到不同工作表中的列
- javascript - 用户首次登录实时firebase数据库时如何创建用户特定数据?