This application is a simple Ruby on Rails project using the Neon Postgres database. It returns a list of authors and books written by them. We illustrate how to generate and run schema change migrations.
To build this project from scratch, check out the guide in Neon's documentation.
You will need the following:
- A Neon account and a project
- Ruby 3.0 or higher
- Clone this repository:
git clone https://github.com/neondatabase/guide-neon-rails
- Navigate to the project directory and install the project dependencies:
cd guide-neon-rails
bundle install
- Create a
.env
file in the root of the project and add the following environment variable with your Neon database URL:
DATABASE_URL=
- Run the Rails database migrations:
rails db:migrate
- Seed the database with sample data:
rails db:seed
- Start the Rails server:
rails server
- Visit
http://localhost:3000
in your browser to see the list of authors and books. Or use curl to see the html payload in your terminal:
# Page with the list of authors
curl http://localhost:3000/authors
# Page with the list of books by author with id 1
curl http://localhost:3000/books/1