简体   繁体   English

Ruby on Rails接受发布请求

[英]Ruby on Rails Accept post request

I need to create a Rails app that will accept a Post request from a mobile client and store the information sent with the request. 我需要创建一个Rails应用程序,该应用程序将接受来自移动客户端的Post请求并存储随请求发送的信息。 I'll be using Ajax to send the request. 我将使用Ajax发送请求。 The request is sent with the following parameters: latitude(float) longitude(float) timestamp(Javascript Date object) 使用以下参数发送请求:latitude(float)经度(float)时间戳(Javascript Date对象)

I've already created a data model with the appropriate fields using rails generate resource, but I'm not sure how to get Rails to accept the Post request and create an object with the necessary information. 我已经使用rails generate resource创建了一个包含相应字段的数据模型,但我不确定如何让Rails接受Post请求并创建一个包含必要信息的对象。 How should I edit the code Rails generated to make this happen? 我应该如何编辑生成的代码Rails以实现此目的?

Thanks, and I apologize for asking such an elementary question. 谢谢,我为提出这样一个基本问题而道歉。

Hard to tell how much you know about Rails from this question, but this is all really basic Rails functionality, so you kindof need to start from the beginning... if you do these two tutorials, you'll be able to get started: 很难从这个问题中了解你对Rails的了解程度,但这都是非常基本的Rails功能,所以你需要从头开始......如果你做这两个教程,你就可以开始了:

  1. Learn Rails Controllers 学习Rails控制器
  2. Learn Rails Routing 学习Rails路由

Then give it a shot creating a new controller and some routes that match what you're looking for, then you can use a mozilla plugin like RESTClient to test your routes with some dummy data. 然后尝试创建一个新的控制器和一些匹配您正在寻找的路径,然后您可以使用像RESTClient这样的mozilla插件来测试您的路由与一些虚拟数据。

But seriously, first step here is "Learn Rails". 但严重的是,这里的第一步是“学习Rails”。 :) :)

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

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