I would like to know if there is a way to connect to PostgreSQL, so I only read the data of the tables that are already created.
I'm developing an API, which will read into a particular database, and return an XML, for example.
I would like to know if there is a way to connect to PostgreSQL, so I only read the data of the tables that are already created.
I'm developing an API, which will read into a particular database, and return an XML, for example.
Yes, Rails was made to support legacy databases as well, but you will have to make additional settings.
First, set the config/database.yml
file to your bank settings.
When generating models and scaffold, use the --no-migration
option to avoid creating tables (which already exist):
rails g model post title text:text --no-migration
rails g scaffold post title text:text --no-migration
Then manually set the table name and primary key:
class Product < ActiveRecord::Base
self.table_name = "PRODUCT"
self.primary_key = "product_id"
end
If you are going to use TDD, also configure the fixture file in the Model TestCase:
class FunnyJoke < ActiveSupport::TestCase
set_fixture_class funny_jokes: Joke
fixtures :funny_jokes
...
end
Remember, the Rails guide is your friend: link
Source: link