Rails association help

别等时光非礼了梦想. 提交于 2019-12-13 05:18:37

问题


Hey I made a scaffold called pictures, but now I need to it to have many tags. I want it to be so that you can do something like click add tag then fill in a tag, then click add tag ..., this would be in pictures/new and edit, and maybe show. I don't have a clue how to do this and I am not that great in rails, so be very clear if you can. (maybe there is something in rails like a button that if you click it you execute a function, even then I'm not sure how to go about this) I am using rails 3.


回答1:


This is something you need.:

  1. http://railscasts.com/episodes/196-nested-model-form-part-1

  2. http://railscasts.com/episodes/197-nested-model-form-part-2




回答2:


Kevin,

I think task number one is to read up on Rails ActiveRecord associations here:

http://guides.rubyonrails.org/association_basics.html

Once you have your associations right, I would make tags a sub-resource of pictures in your routes file. This would allow you to do a POST to :tags with a route like /pictures/{id}/tags



来源:https://stackoverflow.com/questions/7592138/rails-association-help

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