Is it possible to edit different models from the same form when three of the four are nested? How?
How do you handle multiple models in a form? I know that nested models exist, but I'm not su开发者_JAVA技巧re if this is the same situation. Sorry, a bit new to Rails.
In my situation, a project profile has fields such as title, date, description, as well as moderators. Moderators reside on their own model however and this is also updated. Then there's the File (name, filetype, etc.) and Contact (first_name, last_name, etc.) model which also belong to a project profile.
Here are the pseudo-relations between the models in case: project_profile has_many moderators project_profile has_many files project_profile has_one contact
I would like to be able to edit all four from one form. How is this possible? Thanks!
Rails 3.0.7 Ruby 1.9.2
It's possible, it's called nested_attributes
.
See tutorial here: http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes
Or screencast here: http://railscasts.com/episodes/196-nested-model-form-part-1
精彩评论