0

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

Pins tables:

+----------------+---------------+------+-----+---------+----------------+
| 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    |                |
+----------------+---------------+------+-----+---------+----------------+
Yogzzz
  • 2,735
  • 5
  • 36
  • 56
  • What does the output of `describe pins;` in the mysql console look like? – Brian Jun 13 '12 at 23:55
  • If you are looking for a low hassle quickie solution, you may want to try either https://github.com/sferik/rails_admin or http://activeadmin.info/ . But, not sure how that type column is going to behave. – Brian Jun 14 '12 at 00:10

3 Answers3

1

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.

x1a4
  • 19,417
  • 5
  • 40
  • 40
  • Is there anything that I need to explicitly state in my model? After configuring the database in my yml file, do I just run a migration? or should I do a schema dump and a seed load then a migration? Thanks! – Yogzzz Jun 13 '12 at 23:32
  • If your database and table already have data in them, you don't need to migrate or seed. Migrations are for changing the database schema (adding/removing columns or tables, adding indexes, etc.) and seeding is for adding in initial data that your app might expect to already exist. – x1a4 Jun 14 '12 at 00:05
  • I get the impression Yogi is looking to scaffold the whole thing (e.g. controllers, views etc). – Brian Jun 14 '12 at 00:08
  • Yeah, I was hoping to scaffold the whole thing...however the gems you suggested look really interesting. – Yogzzz Jun 14 '12 at 00:15
  • I hope it works out for you. They can be a bit testy which is why I prefer not to use them, but if quick & dirty is your goal - march forward! – Brian Jun 14 '12 at 00:20
  • You may have to look into adding some of other standard fields like created_at and updated_at as well – DVG Jun 14 '12 at 01:34
1

Did you try to use the database.yml of your project on the newer one that you're creating? Doing that and keeping the same class names in the newer project may work.

Taryn
  • 242,637
  • 56
  • 362
  • 405
David
  • 388
  • 1
  • 14
1

All you have to do is open up config/database.yml and adjust the development / production database information to the one you're already using. Assuming that your models and migrations point to tables with identical names, you shouldn't have to change anything else in your program.

Max Scheiber
  • 173
  • 1
  • 9