ruby-on-rails - RoR 用户通过 JSON 添加

标签 ruby-on-rails database json post

我们通过 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/

相关文章:

ruby-on-rails - 三列有序列表

json - Go中的排序接口(interface)

java - 使用 Json Net 解析单个整数

mysql - 验证 2 个数据库的免费工具

mysql - 从cmd上传大文件到Mariadb

c# - 在 Newtonsoft JSON.NET 模式中禁用空类型

ruby-on-rails - 为什么结果返回十六进制而不是实际值?

ruby-on-rails - Puma 有类似 Apache 的 "Location"标签吗?

ruby-on-rails - Rails 3 -reject_if 过程未捕获空白字段

javascript - MongoDB 和 Meteor - 插入嵌套数组的查询不起作用,没有抛出错误