Ruby on Rails project that implements a basic association between models using Active Record
Explore the docs »
View demo
·
Report bug
·
Request feature
The project was developed using the following technologies:
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
Install the following to get this project running in your machine:
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
Project Link: https://github.com/YairFernando67/sample_app
👤 Yair Fernando Facio
- Github: @YairFernando67
- Twitter: @YairFernando18
- Linkedin: softwaredeveloperyairfacio
- Email: yair.facio11@gmail.com
- Portfolio: softwaredeveloper
👤 Jaak Kivinukk
- Github: @Jaakal
- Twitter: @JKivinukk
- Linkedin: full-stack-developer
- Email: jaak.kivinukk@gmail.com
Contributions, issues and feature requests are welcome!
Feel free to check the issues page.
Give a ⭐️ if you like this project!