[英]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.因为我是 RoR 的新手,所以我无法真正理解如何做到这一点。我有一个Price
model,这是我想用于 forms 的唯一表。 I want to have 2 other MVCs that are UserData
and Search
.我想要另外两个 MVC,它们是UserData
和Search
。
The scenario is Users can input Prices and these Prices have 3 places to go.场景是用户可以输入价格,这些价格在 go 中有 3 个位置。 It can be their Data area, Search area or both areas.它可以是他们的数据区域、搜索区域或两个区域。 But the twist is Data area will have my parts on the form 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?那么如何设置它以便我将我的价格表单用于其他 2 个 MVC?
EDIT:编辑:
User
has_many Prices
User
has_many Prices
UserData
has_many Prices
and Category belongs_to UserData
UserData
has_many Prices
和类别属于_to UserData
Search
has_many Prices
and Tag
belongs_to Search
Search
has_many Prices
和Tag
belongs_to Search
Price
Form = price name, date, and cost only. Price
形式 = 价格名称、日期和成本。
UserData
+ Price Form + Category
model = price name,date,cost and category .用户数据 + 价格表 + Category
UserData
= 价格名称、日期、成本和类别。
Search
+ Price form + Tag
Model = price name,date,cost and tags of price ( vegetables, candy?) Search
+ 价格表 + Tag
Model = 价格名称、日期、成本和价格标签(蔬菜、糖果?)
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嗨,如果您使用的是 rails 3,请检查http://railscasts.com/episodes/269-template-inheritance
如果旧版本您应该在您的视图目录下创建shared
文件夹并将部分_price_form
放置在页面http://guides.rubyonrails.org/layouts_and_rendering.html
- 渲染指南
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现在如何为多个模型创建一个表格以便更好地理解我建议你检查这两个 railscasts
http://railscasts.com/episodes/196-nested-model-form-part-1
http://railscasts.com/episodes/197-nested-model-form-part-2
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 http://stackoverflow.com/questions/5717421/accepts-nested-attributes-for-practical-form-use-for-in-rails-3
也可能有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.