Contributors Forks Stargazers Issues LinkedIn LinkedIn Hireable


Rails Application implementing Active Record Associations

Ruby on Rails project that implements a basic association between models using Active Record
Explore the docs »

View demo · Report bug · Request feature

Table of Contents

About The Project

Built With

The project was developed using the following technologies:

Required Installations

Prerequisites

This project runs on Ruby and Ruby on Rails

  • Ruby
  • Ruby on Rails

After installation, run ruby -v to make sure Ruby installed correctly. Example:

$ ruby -v
ruby 2.6.4p104 (2019-08-28 revision 67798) [x86_64-linux]

Also make sure that Rails is installed running rails -v. Example:

$ rails -v
Rails 6.0.2.1

Installing

Install the following to get this project running in your machine:

Instructions

Follow these steps:

Clone the repository

user@pc:~$ git clone https://github.com/Jaakal/building-with-active-record

On the console go to the folder that was created

user@pc:~$ cd building-with-active-record
$ bundle install --without production

Next migrate the database:

$ rails db:migrate

Run this command if you encountered a problem running rails db:migrate

$ bundle exec rails db:migrate

Finally you can test the associations through the rails console:

$ rails console

Code snippet

$ user = User.create(name: "Joe", email: "joe.ruby@gmail.com")
$ post = Post.create(title: "Title for the first post", body: "This is my first content", user_id: user.id)
$ comment = Comment.create(body: "Great post!!", post_id: post.id, user_id: user.id)

Testing the associations

$ User.first.posts
$ User.first.comments
$ Comment.first.user
$ Post.first.user

Contact

Project Link: https://github.com/YairFernando67/sample_app

Screenshot Image

👤 Yair Fernando Facio

Screenshot Image

👤 Jaak Kivinukk

🤝 Contributing

Contributions, issues and feature requests are welcome!

Feel free to check the issues page.

Show your support

Give a ⭐️ if you like this project!