A Rails Blog In VS Code - Quick Start.

How To Create A Blog in VS Code — Part I — RailsSeries#Episode 03

J3
Jungletronics
6 min readJul 11, 2023

--

How To Run a Simple_Blog In Rails 7?

Based on: Deanins lessons: 👉️ GitHub

In this post:

You will:

Learn how to get started with a very simple rails 7 frame;

Learn how to build a blog completely from scratch;

Learn routes, models, views, and controllers, on the way;

Plus, we'll deploy our code to heroku production 👌️

This is a good challenge, for sure!

We wish you were with us, it will be fine and fun!

Proof of Concept: All 12 steps are executed from start to finish!

Hi, Welcome! Let’s get started!

00#step —First, Environment — Go to your fresh Ubuntu 23.04👌️Terminal and type it all:

fig-1. Prerequisites to reproduce this code: Ubuntu machine, VSCODE, and Stamina to learn more.

Installing all dependencies 🤌️ :

sudo apt-get update  
sudo apt install git
sudo apt install openssl -y
sudo apt-get install build-essential
sudo apt-get install libz-dev
sudo apt-get install libyaml-dev
apt-get install -y libssl-dev
sudo apt-get install -y libssl-dev
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.12.0

asdf plugin list all
asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git
asdf install ruby latest
asdf list

ruby -version
No version is set for command ruby
Consider adding one of the following versions in your config file at
ruby 3.2.2

asdf local ruby 3.2.2

ruby --version
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]

ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
gem install rails
gem update --system 3.4.16

rails -v
Rails 7.0.6

If you need some more info please consider seeing this post.

Fine! So far, so good! One more step, optional, for sure... Get some plugins for you! Vscode will be at your command! Please follow this post, if you wish…

01#step — On a dedicated directory (mine is RAILS_PROJECTS) open your Linux Terminal and type:

rails new rails-blog-demo
cd rails-blog-demo

02#step — Welcome pages:

rails g controller pages home about
code . # open vscode right away!

03#step — Open config > routes.rb :

Rails.application.routes.draw do
get "home", to: "pages#home"
get "about", to: "pages#about"
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

# Defines the root path route ("/")
root "pages#home"
end

04#step — Go to Gemfile To Set Up Ruby on Rails with Postgres, type:

// transfer sqlite3 to devel and for production use pg (heroku needs it...)
...
group :development, :test do
# Use sqlite3 as the database for Active Record
gem "sqlite3", "~> 1.4"
...
end

group :production do
gem "pg"
end
...

05#step — On Linux Terminal type:

sudo apt install postgresql postgresql-contrib libpq-dev

06#step — On Vscode Terminal, type bundle install:

bundle install

07#step — Test your app:

rails s

08#step — Put your server down:

Ctrl + c

09#step — For Heroku CLI, Go to Your Linux terminal and type:

sudo apt-get install curl
curl https://cli-assets.heroku.com/install-ubuntu.sh | sh

heroku -v
heroku/8.1.9 linux-x64 node-v16.19.0

10#step — Go to Your Git Repo and create a blank project named rails_blog_demo or whatever you’d like to call it…

11#step — Git Commands — On Linux Terminal, Set your SSL key:

ssh-keygen -t ed25519 -C "giljr.2009@gmail.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub

Paste it to your Git account:
https://github.com/settings/keys

12#step — Complete step-by-step Heroku and Git commands:

Go to j3@JAYTHREE:~/Documents/rails_projects/rails-blog-demo$ directory:


git init
git checkout -b master
git branch -M master

git remote add origin git@github.com:giljr/rails_blog_demo.git
or
Whatever your Repo name is...

heroku create
heroku rename j3_rails_blog_demo
or
heroku apps:rename --app agile-ridge-44818 j3-rails-blog-demo
heroku stack:set heroku-20

git remote -v
heroku https://git.heroku.com/j3-rails-blog-demo.git (fetch)
heroku https://git.heroku.com/j3-rails-blog-demo.git (push)
origin git@github.com:giljr/rails_blog_demo.git (fetch)
origin git@github.com:giljr/rails_blog_demo.git (push)

git status
git add -A
git commit -m ":tada: Initial Commit"
git push -u origin master
or
git push --set-upstream origin master
or
git push --set-upstream --force origin master
or
git push -u origin master

git push heroku master
heroku open

Manually visit:
https://j3-rails-blog-demo-5a0a55d44e12.herokuapp.com/
in your favorite browser 🥰️

There you have it:

This content is displayed on Heroku. You’re now connected! Congratulations! Kindly watch the video provided above.

That’s all folks!

In the next post, we will be styling the pages…

Bye for now!

👉️rails_blog_v1

[chatGPT]

Writing posts can be a valuable learning
tool for programming, and there are
several reasons why it is important:

Reinforcing knowledge:

When you write a post explaining a programming
concept or solving a problem, you need to have
a solid understanding of the topic. This
process of articulating your thoughts and
explaining the concepts helps reinforce
your own understanding.

Organizing thoughts:

Writing a post requires you to structure
your thoughts and present information in
a clear and logical manner. This process
can help you organize your understanding
of a programming topic, making it easier
to recall and apply in the future.

Filling knowledge gaps:

While attempting to explain a concept
in a post, you may realize that there
are gaps in your understanding or areas
where you need to do further research.
By identifying these knowledge gaps,
you can actively work on filling them,
thereby improving your overall
understanding of programming.

Learning through teaching:

The act of teaching or explaining a
concept to others is a powerful
learning strategy. When you write a
post, you essentially play the role of
a teacher, which requires you to dive
deep into the topic, find different ways
to explain it, and anticipate potential
questions or misunderstandings.
This process deepens your understanding
and helps you grasp the intricacies
of the subject matter.

Engaging with the programming community:

Sharing your knowledge through blog posts
or tutorials allows you to interact
with the programming community.
By receiving feedback, answering questions,
and engaging in discussions,
you gain exposure to different perspectives,
learn from others, and further
enhance your programming skills.

In summary, writing posts about programming
helps solidify your knowledge, organize
your thoughts, identify knowledge gaps,
learn through teaching, and engage with
the programming community.
It is a valuable practice for both your
personal growth and for contributing
to the learning and development of others.

Related Posts:

00# Episode — RailsSeries — Installing Ruby on Rails Using ASDF — Why ASDF is Better Than RBENV for Rails Bootstrap App?

01# Episode — RailsSeries — How To Send Email In Rails 7? — User Registration and Onboarding.

02# Episode — RailsSeries — 14 Ruby Extensions 4 Vs Code — Based On This Deanin’s video.

03# Episode — RailsSeries — A Rails Blog In VS Code — Quick Start — How To Create A Blog in VS Code — Part I (this one)

04# Episode — RailsSeries — A Rails Blog In VS Code — Styling — How To Create A Blog in VS Code — Part II

05# Episode — RailsSeries — A Rails Blog In VS Code — Create Posts — How To Create A Blog in VS Code — Part III

06# Episode — RailsSeries — A Rails Blog In VS Code — Posts Tips&Tricks — How To Create A Blog in VS Code — Part IV

07# Episode — RailsSeries — A Rails Blog In VS Code — Devise — How To Create A Blog in VS Code — Part V

08# Episode — RailsSeries — A Rails Blog In VS Code — Add Comments to Post — How To Create A Blog in VS Code — Part VI

09# Episode — RailsSeries — Rails Blog In VS Code — Using Stimulus — How To Create A Blog in VS CodePart VII

10# Episode — RailsSeries — Rails Blog In VS Code — Noticed V1 — Notifications for your Ruby on Rails app — Part VIII

11# Episode — RailsSeries — Rails Blog In VS Code — Noticed V2 — Notifications for your Ruby on Rails app — Part IX

For v1 let’s Tag it all!

git tag -a rails_blog_v1 -m "Blog in Rails 7 - v1.0:  Go to  https://j3-rails-blog-demo-5a0a55d44e12.herokuapp.com/" -m "0- Setting up dependencies on Ubuntu 23.04 (Lunar Lobster);" -m "1- Create a new project, use generate controller;" -m "2- Config routes.rb, change Gemfile;" -m "3- Running Heroku CLI and git commands;" -m "4- Upload Rails 7 project to heroku." -m "Thank you for downloading this project 😍️" 
git push origin rails_blog_v1

--

--

J3
Jungletronics

Hi, Guys o/ I am J3! I am just a hobby-dev, playing around with Python, Django, Ruby, Rails, Lego, Arduino, Raspy, PIC, AI… Welcome! Join us!