¿Cómo haces que Rails proporcione acceso a una base de datos EXISTENTE?

All of the Rails tutorials I've looked at seem to revolve around creating a new database and then making the contents of the database accessible through the web page. You get access to the user list after you enter the following commands:

    rails generate scaffold User name:string email:string
    rake db:create:all
    rake db:migrate

But what if you already created the user database with data in it? What is the alternative procedure for providing access to the user database?

UPDATE 1: I'm using a Postgres database.

preguntado el 25 de abril de 13 a las 05:04

The URL, of course, is localhost: 3000 / usuarios . I wasn't allowed to post the URL in the question. -

2 Respuestas


For migrating all the data you'll have to use an external tool, depending on your database type.

Or you can export all the data to JSON and then import it, which could be done relatively easy, since Ruby can easily import and export JSON.

You can export your current data to JSON, directly by running a native SQL query selecting the users data and then converting it to JSON.

Respondido 25 Abr '13, 06:04

What external tools are available for migrating data? Are there any tutorials or other exercises that provide examples of this? - jhsu802701

What exactly are you looking for

If u want to use database of your choice from postgres you need to specify its adapter ,dbname,username and password in database.yml

If u want to migrate all ur data from one db to another db u should create a dump of db and restore that dump in another ...

now steps for dump are

The idea behind this dump method is to generate a text file with SQL commands

pg_dump dbname > outfile

Restoring the Dump

The text files created by pg_dump are intended to be read in by the psql program. The general command form to restore a dump is

psql dbname < infile

Puedes referir



Respondido 25 Abr '13, 07:04

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.