简体   繁体   English

与Rails3同时插入多行

[英]Inserting Multiple Rows Simultaneously with Rails3

We have an existing mysql database and a php front end which we're currently porting to a RoR3 application using Datamapper. 我们有一个现有的mysql数据库和一个php前端,目前正在使用Datamapper移植到RoR3应用程序。

We need to insert multiple rows with a single commit, each using the same name. 我们需要通过一次提交插入多个行,每个行都使用相同的名称。 For example, if I look at the groups table, we have this structure: 例如,如果我查看groups表,我们将具有以下结构:

+-----------+------------------+------+-----+---------+----------------+
| Field     | Type             | Null | Key | Default | Extra          |
+-----------+------------------+------+-----+---------+----------------+
| id        | int(11) unsigned | NO   | PRI | NULL    | auto_increment |
| groupname | varchar(64)      | NO   | MUL |         |                |
| attribute | varchar(64)      | NO   |     |         |                |
| op        | char(2)          | NO   |     | ==      |                |
| value     | varchar(253)     | NO   |     |         |                |
+-----------+------------------+------+-----+---------+----------------+

And the content looks like this: 内容如下所示:

+----+---------------------------+-------------------+----+------------+
| id | groupname                 | attribute         | op | value      |
+----+---------------------------+-------------------+----+------------+
|  1 | RADIUS-Disabled-Users     | Auth-Type         | := | Reject     |
|  2 | 30-minutes                | Huntgroup-Name    | == | xxx        |
|  3 | 30-minutes                | Simultaneous-Use  | := | 1          |
|  4 | 30-minutes                | Max-Daily-Session | := | 1800       |
|  7 | silver                    | Simultaneous-Use  | := | 25         |
+----+---------------------------+-------------------+----+------------+

As you can see, we have multiple rows with the same name, each with a different attribute and value. 如您所见,我们有多个具有相同名称的行,每行具有不同的属性和值。

In our view, I need a name field followed by a drop down menu for the attribute and a field for the value. 在我们看来,我需要一个名称字段,后跟一个下拉菜单(用于属性)和一个字段(用于值)。 Most importantly we need to be able to insert multiple rows in one move. 最重要的是,我们需要能够一口气插入多行。

Can anyone point me in the right direction? 谁能指出我正确的方向?

No Problem,... Would be much code to explain but thanks god theres a raislcast series about this... 没问题,...将会有很多代码来解释,但是感谢上帝,对此有一个raislcast系列...

http://railscasts.com/episodes/73-complex-forms-part-1 http://railscasts.com/episodes/73-complex-forms-part-1
http://railscasts.com/episodes/74-complex-forms-part-2 http://railscasts.com/episodes/74-complex-forms-part-2
http://railscasts.com/episodes/75-complex-forms-part-3 http://railscasts.com/episodes/75-complex-forms-part-3

hf,... HF,​​...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM