简体   繁体   English

通过休息api填充模型

[英]populating model through rest api

I'm currently working on a rails app where I have two model classes, Account and User. 我目前正在开发一个rails应用程序,我有两个模型类,帐户和用户。 I want to allow users to link their User with account information from other places. 我想允许用户将其用户与来自其他地方的帐户信息相关联。

What I want the user to be able to do is, under my edit user form, I have a list displaying the names of all linked accounts, and a text input for them to add more. 我希望用户能够做的是,在我的编辑用户表单下,我有一个列表,显示所有链接帐户的名称,以及一个文本输入,供他们添加更多。

All I want them to do is fill in one field (account name) and hit a button, and the back end will hit a restful API for that account name, pull back relevant info, and populate an Account model object, linking to the current user. 我希望他们做的只是填写一个字段(帐户名称)并点击一个按钮,后端将为该帐户名称找到一个宁静的API,撤回相关信息,并填充一个帐户模型对象,链接到当前用户。

For example, from the user page I would like the user to be able to type in their twitter handle, and in the back end I'd look up that twitter account id and associate it with that User in my database. 例如,从用户页面我希望用户能够输入他们的Twitter句柄,并在后端我查找该Twitter帐户ID并将其与我的数据库中的该用户相关联。

Where is the right place to have a hook so that I can take an input (twitter handle), fire off a helper method that populates a Account object, and then link that to my current user? 在哪里有一个钩子的正确位置,以便我可以接受输入(推特句柄),触发填充Account对象的辅助方法,然后将其链接到我当前的用户?

我不确定我到底知道你在问什么,但我会尽我所能:如果你的帐户'belongs_to'你的用户模型,使用你的创建或更新方法(取决于你的标准情况)似乎合乎逻辑帐户控制器,用于检索具有帐户数据的JSON,以及客户端解析此答案(使用某些JS)。

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

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