我们通过 POST 接收 json 对象,格式为 {email,password,hash,currentDate,companyName}
需要使用 RoR 方法在我们的数据库 (postrege) 中创建用户。
请帮助实现该方法。
最佳答案
我建议您阅读 JSON/XML parameters “ Action Controller 概述” rails 指南的一部分。也许您无法修改获取的 JSON,您必须查看 config.wrap_parameters
选项。
如果你收到一个像这样的 JSON 对象
{"user" : {"email": "user@example.com",
"password": "secret",
"hash": "sd98ds789fsd",
"currentDate": "the-current-date",
"companyName": "Umbrella corp."}}
你会像往常一样在参数散列中找到它:
# This will be "user@example.com"
params[:user][:email]
# This will contain "secret"
params[:user][:password]
关于ruby-on-rails - RoR 用户通过 JSON 添加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10276435/