I know nothing about PostgreSQL and a little about Ruby on Rails. I know Ruby. I have experience with the command line.
I'm interning and I was told to build a Rails API that loads data into a two-dimensional array from PostgreSQL database. The API is meant to have methods to get certain pieces of the data given a certain index.
I don't know how/where to begin despite how simple it should be. I have no experience with databases. Please point me in the right direction to get this set up and started.
Starting with Rails 5, you can generate a Rails API only application. Just use the following command:
rails new project-name-here --api --database=postgresql
I assume that you have ruby, rails and postgresql installed.
rails db:create # creating DB
Running rails generate scaffold User first_name:string last_name:string
, it will generate all files needed for User
model.
A scaffold in Rails is a full set of model, database migration for that model, controller to manipulate it, views to view and manipulate the data, and a test suite for each of the above.
rails db:migrate # migrating the DB
rails s # starting the server
Now, you can access the /users
endpoint. Do not forget to update controllers actions with relevant data.
A detailed example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With