I made this project to learn Ruby and Rails so I could be better prepared for interviews at companies that use this program stack
Make sure you have Ruby and Rails installed on your machine. Once you do, you can use gem in your
- Run this in terminal/command prompt: gem install bundler
- Run this in terminal/command prompt: bundle install
To enable hot module replacement, run this command in the terminal/command prompt
- Run this in terminal/command prompt: bundle exec guard
- Clone the reop
- Run this in terminal/command prompt: rails s
- Go to http://localhost:3000/ in your browser
- Run this in terminal/command prompt: rake routes
To generate a controller called post_controller.rb run this in terminal/command prompt: rails g controller posts
To generate a model called Post with fields title and content run this in terminal/command prompt: rails g model Post title:string content:text
To migrate the rails database run this in terminal/command prompt: rails db:migrate
To generate your own migration run this in terminal/command prompt: rails g migration AddPostIdToComments
-
To access rails console run this in terminal/command prompt: rails console
-
Then to access individual models like Post by running: @post = Post
-
Then connect to that models data by running: @post.connection
-
Then view all the records of that model by running: @post.all
-
To create a reference to an individual record by its Id run: Post.find(8)
-
Now running @post should return that individual post which you can now edit the values of like this: @post.title "New title", and then run this to save the changes: @post.save