How can i add values for a field from another model in rails?

Deadly 提交于 2019-12-25 05:55:30

问题


I have a user model and language model where the language model contains list of languages and the user model contains the information of the user. In user model there is a field called language where the user should select a language from the language model. And for all these i do not have form and i want to pass the id of the language when creating new user and it should save the language for the user. I use curl to create and update.

So please tell me how i can do this? Please help me.

Thanks in advance.


回答1:


I think nested attribute is what you need. You can learn more about it here : Active Record Nested Attributes

Additionally for simulating nested attribute calls using curl, you can look at this post :

Simulate a form post with nested resources arrays using curl



来源:https://stackoverflow.com/questions/13680792/how-can-i-add-values-for-a-field-from-another-model-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!