【发布时间】:2015-06-10 18:17:49
【问题描述】:
我有一个命令可以将一些 json 发布到 rails url:
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d ' {"user":{"first_name":"firstname","last_name":"lastname","email":"email@email.com","password":"app123","password_confirmation":"app123"}}' http://localhost:3000/maps
我的控制器中有一个方法创建:
def create
#@map = Map.new(map_params)
#@json = ActiveSupport::JSON.decode(open('jsonfeed').read)
@result = JSON.parse string #parse json, but where to get that json first
respond_to do |format|
if @map.save
format.json {
#render :show, status: :created, location: @map
}
else
format.json { render json: @map.errors, status: :unprocessable_entity }
end
end
end
如何将 json 发送到 rails。我认为 JSON.parse 将解析我的 json 并返回哈希参数,但首先如何获取该 json。
【问题讨论】:
标签: ruby-on-rails json ruby-on-rails-4