简体   繁体   English

如何将一个表单/表格用于多个 MVC?

[英]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,它们是UserDataSearch

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 PricesTag 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.

相关问题 如何使用Active Admin的表单块来更新跟踪资源中的属性何时更新的表? - How can I use Active Admin's form block to update a table that tracks when an attribute in a resource is updated? 如何在 simple_form 中使用多个 HTTP 方法? - How can I use multiple HTTP methods in simple_form? 如何在一个型号上使用多个控制器? - How can i use multiple controller with one model? 如果该表的关联表的列之一不满足条件,如何忽略该表中的一行? - How can I ignore a row from a table if one of it's associated table's column fail to meet the condition? 如何在表格中使用 check_box 以便可以访问数组中的表格属性? - How do I use check_box in a table form so that I can access the table attributes in an array? 如何在一个表单中将嵌套表单用于多个模型? - How to use a nested form for multiple models in one form? 如何在form_for中使用多个“一对多”嵌套属性 - How do I use multiple “one-to-many” nested attributes in form_for 如何将两个属性组合成一个表来构成一个“事件”? - How can I combine two attributes form a table to make one “event”? Rails 3 + Tumblr API:如何使用一种表单同时编辑多个帖子? - Rails 3 + Tumblr API: How can I edit multiple posts at the same time with one form? 如何在 label 中使用嵌套属性的翻译,以便只维护一个翻译? - How can I use a nested attribute's translation in a label so I only maintain one translation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM