使用现有的 mysql 数据库创建一个新的 Rails 应用程序 [英] Create a new Rails app with an existing mysql Database

查看:42
本文介绍了使用现有的 mysql 数据库创建一个新的 Rails 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个现有的 mysql 数据库,并且想设置一个新的 Rails,以便我的客户可以查看和编辑数据库中的记录.如何设置链接到现有数据库的脚手架.db 名称是Products",只有一张表叫做pins".

I have an existing mysql database set up, and would like to set up a new rails up simply so my client can view and edit the records in the db. How can I set up a scaffold linked to my existing db. The db name is "Products" and has just one table called "pins".

别针表:

+----------------+---------------+------+-----+---------+----------------+
| Field          | Type          | Null | Key | Default | Extra          |
+----------------+---------------+------+-----+---------+----------------+
| id             | int(11)       | NO   | PRI | NULL    | auto_increment |
| type           | text          | YES  |     | NULL    |                |
| title          | text          | YES  |     | NULL    |                |
| description    | text          | YES  |     | NULL    |                |
| price          | text          | YES  |     | NULL    |                |
| img_src        | text          | YES  |     | NULL    |                |
| source         | text          | YES  |     | NULL    |                |
| sr_id          | text          | YES  |     | NULL    |                |
| category       | varchar(1000) | YES  |     | NULL    |                |
| pinner         | text          | YES  |     | NULL    |                |
| pinner_id      | text          | YES  |     | NULL    |                |
| board_cat      | text          | YES  |     | NULL    |                |
| board_name     | text          | YES  |     | NULL    |                |
| board_url      | text          | YES  |     | NULL    |                |
| like_count     | bigint(20)    | YES  |     | NULL    |                |
| repins_count   | bigint(20)    | YES  |     | NULL    |                |
| comments_count | bigint(20)    | YES  |     | NULL    |                |
| pinned_count   | bigint(20)    | YES  |     | NULL    |                |
| actions_count  | bigint(20)    | YES  |     | NULL    |                |
| error_404      | bigint(20)    | YES  |     | NULL    |                |
| pin_at         | text          | YES  |     | NULL    |                |
| social_rank    | bigint(20)    | YES  |     | NULL    |                |
| created_at     | text          | NO   |     | NULL    |                |
| updated_at     | text          | NO   |     | NULL    |                |
| isgiftable     | int(11)       | YES  |     | NULL    |                |
| sr_id_int      | bigint(20)    | YES  |     | NULL    |                |
+----------------+---------------+------+-----+---------+----------------+

推荐答案

您可以在 config/database.yml 中设置数据库名称.您需要一个 Pin 模型,它会自动映射到正确的表格.数据库中的字段会自动映射到模型中的属性,但如果字段的名称不稳定,您可能需要编写一些胶水.

You can set the database name in config/database.yml. You'll want to have a Pin model which will map to the correct table automatically. The fields in the database will map to attributes in the model automatically, though you may need to write some glue if the names of the fields are wonky.

如果没有更多信息,很难给出比这更多的建议.

It's hard to give more advice than this without more info.

这篇关于使用现有的 mysql 数据库创建一个新的 Rails 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆