简体   繁体   English

Rails发布请求和响应

[英]Rails Post Request and Response

I'm not to familiar with HTTP so forgive me if this is a dumb question. 我不熟悉HTTP,如果这是一个愚蠢的问题,请原谅我。

I'm working on creating a backend rails api to store/validate users in my android app. 我正在创建一个后端Rails api,以在我的android应用中存储/验证用户。 What I'm trying to do is the first time the user logs in, I send a post request to my rails server to create a new user. 我想做的是用户首次登录,我向Rails服务器发送发布请求以创建一个新用户。 After creating the user I'd like to send the app back the user's auth_token (which will then be used in the future to validate anything the user does). 创建用户后,我想将应用发送回用户的auth_token(以后将用于验证用户所做的任何事情)。

So my question is this - can I send a string or json back after receiving a post request? 所以我的问题是-收到发布请求后我可以发回字符串或json吗? If you can point me to a SO or guide, I'd appreciate that as well (I haven't found much so far). 如果您可以向我介绍SO或指南,我也将不胜感激(到目前为止,我还没有发现很多东西)。

If you can't do that, one other idea I had was to create the auth_token in the Android app, store it and send that to the server with the post requestion and set that as the user's auth_token. 如果您无法做到这一点,那么我的另一种想法是在Android应用中创建auth_token,将其存储并通过发布请求将其发送到服务器,并将其设置为用户的auth_token。

Thanks in advance! 提前致谢!

The post request will take you to the create method in the users_controller. 发布请求将带您进入users_controller中的create方法。 After you create the user, you can do anything else that you want. 创建用户后,您可以执行其他任何操作。 The code should look something like this: 代码应如下所示:

class UsersController < ApplicationController
def create
    ...
    render json: ...
end
end

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

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