简体   繁体   English

如何通过Rails上的json接受发布请求?

[英]How to accept post request via json on rails?

I have a controller which accepts both html and json format data. 我有一个控制器, 可以接受 html和json格式的数据。 I want to know how to accept the data of json format from the POST request from the browser's REST client . 我想知道如何从浏览器的REST客户端POST请求中接受json格式的数据。 Null values are getting stored in the database. 空值将存储在数据库中。 How to convert Json format data into string to store it in the database? 如何将Json格式的数据转换为字符串以将其存储在数据库中? I have used rabl gem to filter json contents. 我使用了rabl gem来过滤json内容。 Ruby on Rails . Ruby on Rails

You might want to take a look at the serialize class method: 您可能要看一看serialize类方法:

http://apidock.com/rails/ActiveRecord/Base/serialize/class http://apidock.com/rails/ActiveRecord/Base/serialize/class

This allows one to easily save the incoming JSON format and parse it to a Hash when retreiving it from the database. 这样一来,当从数据库中检索传入的JSON格式时,可以轻松保存传入的JSON格式并将其解析为Hash。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM