How can i use a one form/table for multiple MVC's?
I cant really wrap my head around how to do this since I'm new at RoR.I have a Price
model which is the only table i want to use for forms. I want to have 2 other MVCs that are UserData
and Search
.
The scenario is Users can input Prices and these Prices have 3 places to go. It can be their Data area, Search area or both areas. But the twist is Data area will have my parts on the for开发者_Go百科m like the category of price and same goes with the Search area, that form you can put tags on it.
So how do i set it up so i am using my Prices form for the other 2 MVCs?
EDIT:
User
has_many Prices
UserData
has_many Prices
and Category belongs_to UserData
Search
has_many Prices
and Tag
belongs_to Search
Price
Form = price name, date, and cost only.
UserData
+ Price Form + Category
model = price name,date,cost and category.
Search
+ Price form + Tag
Model = price name,date,cost and tags of price ( vegetables, candy?)
Hi If you're using rails 3 check http://railscasts.com/episodes/269-template-inheritance
if older version you should create folder shared
under your views directory and place there partial _price_form
and render it on page http://guides.rubyonrails.org/layouts_and_rendering.html
- guide on rendering
If your have any connections between models please post its description
now how to have one form for several models for better understanding I would advise you to check these 2 railscasts
http://railscasts.com/episodes/196-nested-model-form-part-1
http://railscasts.com/episodes/197-nested-model-form-part-2
also http://stackoverflow.com/questions/5717421/accepts-nested-attributes-for-practical-form-use-for-in-rails-3
may be helpful
精彩评论