diff --git a/blog_on_rails/.gitignore b/blog_on_rails/.gitignore
new file mode 100644
index 0000000..18b43c9
--- /dev/null
+++ b/blog_on_rails/.gitignore
@@ -0,0 +1,27 @@
+# See https://help.github.com/articles/ignoring-files for more about ignoring files.
+#
+# If you find yourself ignoring temporary files generated by your text editor
+# or operating system, you probably want to add a global ignore instead:
+# git config --global core.excludesfile '~/.gitignore_global'
+
+# Ignore bundler config.
+/.bundle
+
+# Ignore all logfiles and tempfiles.
+/log/*
+/tmp/*
+!/log/.keep
+!/tmp/.keep
+
+# Ignore uploaded files in development
+/storage/*
+!/storage/.keep
+
+/node_modules
+/yarn-error.log
+
+/public/assets
+.byebug_history
+
+# Ignore master key for decrypting credentials and more.
+/config/master.key
diff --git a/blog_on_rails/.ruby-version b/blog_on_rails/.ruby-version
new file mode 100644
index 0000000..25c81fe
--- /dev/null
+++ b/blog_on_rails/.ruby-version
@@ -0,0 +1 @@
+ruby-2.5.1
\ No newline at end of file
diff --git a/blog_on_rails/Gemfile b/blog_on_rails/Gemfile
new file mode 100644
index 0000000..2612127
--- /dev/null
+++ b/blog_on_rails/Gemfile
@@ -0,0 +1,60 @@
+source 'https://rubygems.org'
+git_source(:github) { |repo| "https://github.com/#{repo}.git" }
+
+ruby '2.5.1'
+
+# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
+gem 'rails', '~> 5.2.2'
+# Use postgresql as the database for Active Record
+gem 'pg', '>= 0.18', '< 2.0'
+# Use Puma as the app server
+gem 'puma', '~> 3.11'
+# Use SCSS for stylesheets
+gem 'sass-rails', '~> 5.0'
+# Use Uglifier as compressor for JavaScript assets
+gem 'uglifier', '>= 1.3.0'
+# See https://github.com/rails/execjs#readme for more supported runtimes
+# gem 'mini_racer', platforms: :ruby
+
+# Use CoffeeScript for .coffee assets and views
+gem 'coffee-rails', '~> 4.2'
+# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
+gem 'jbuilder', '~> 2.5'
+# Use Redis adapter to run Action Cable in production
+# gem 'redis', '~> 4.0'
+# Use ActiveModel has_secure_password
+gem 'bcrypt', '~> 3.1.7'
+
+# Use ActiveStorage variant
+# gem 'mini_magick', '~> 4.8'
+
+# Use Capistrano for deployment
+# gem 'capistrano-rails', group: :development
+
+# Reduces boot times through caching; required in config/boot.rb
+gem 'bootsnap', '>= 1.1.0', require: false
+gem 'faker'
+gem 'bootstrap'
+gem 'jquery-rails'
+
+group :development, :test do
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
+ gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
+ gem 'pry'
+ gem 'pry-rails'
+ gem 'hirb'
+ gem 'cancancan'
+end
+
+group :development do
+ # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
+ gem 'web-console', '>= 3.3.0'
+ gem 'listen', '>= 3.0.5', '< 3.2'
+ # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
+ gem 'spring'
+ gem 'spring-watcher-listen', '~> 2.0.0'
+end
+
+
+# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
+gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
diff --git a/blog_on_rails/Gemfile.lock b/blog_on_rails/Gemfile.lock
new file mode 100644
index 0000000..14f5ae4
--- /dev/null
+++ b/blog_on_rails/Gemfile.lock
@@ -0,0 +1,217 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actioncable (5.2.2)
+ actionpack (= 5.2.2)
+ nio4r (~> 2.0)
+ websocket-driver (>= 0.6.1)
+ actionmailer (5.2.2)
+ actionpack (= 5.2.2)
+ actionview (= 5.2.2)
+ activejob (= 5.2.2)
+ mail (~> 2.5, >= 2.5.4)
+ rails-dom-testing (~> 2.0)
+ actionpack (5.2.2)
+ actionview (= 5.2.2)
+ activesupport (= 5.2.2)
+ rack (~> 2.0)
+ rack-test (>= 0.6.3)
+ rails-dom-testing (~> 2.0)
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
+ actionview (5.2.2)
+ activesupport (= 5.2.2)
+ builder (~> 3.1)
+ erubi (~> 1.4)
+ rails-dom-testing (~> 2.0)
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
+ activejob (5.2.2)
+ activesupport (= 5.2.2)
+ globalid (>= 0.3.6)
+ activemodel (5.2.2)
+ activesupport (= 5.2.2)
+ activerecord (5.2.2)
+ activemodel (= 5.2.2)
+ activesupport (= 5.2.2)
+ arel (>= 9.0)
+ activestorage (5.2.2)
+ actionpack (= 5.2.2)
+ activerecord (= 5.2.2)
+ marcel (~> 0.3.1)
+ activesupport (5.2.2)
+ concurrent-ruby (~> 1.0, >= 1.0.2)
+ i18n (>= 0.7, < 2)
+ minitest (~> 5.1)
+ tzinfo (~> 1.1)
+ arel (9.0.0)
+ autoprefixer-rails (9.4.2)
+ execjs
+ bcrypt (3.1.12)
+ bindex (0.5.0)
+ bootsnap (1.3.2)
+ msgpack (~> 1.0)
+ bootstrap (4.1.3)
+ autoprefixer-rails (>= 6.0.3)
+ popper_js (>= 1.12.9, < 2)
+ sass (>= 3.5.2)
+ builder (3.2.3)
+ byebug (10.0.2)
+ cancancan (2.3.0)
+ coderay (1.1.2)
+ coffee-rails (4.2.2)
+ coffee-script (>= 2.2.0)
+ railties (>= 4.0.0)
+ coffee-script (2.4.1)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.12.2)
+ concurrent-ruby (1.1.4)
+ crass (1.0.4)
+ erubi (1.7.1)
+ execjs (2.7.0)
+ faker (1.9.1)
+ i18n (>= 0.7)
+ ffi (1.9.25)
+ globalid (0.4.1)
+ activesupport (>= 4.2.0)
+ hirb (0.7.3)
+ i18n (1.2.0)
+ concurrent-ruby (~> 1.0)
+ jbuilder (2.8.0)
+ activesupport (>= 4.2.0)
+ multi_json (>= 1.2)
+ jquery-rails (4.3.3)
+ rails-dom-testing (>= 1, < 3)
+ railties (>= 4.2.0)
+ thor (>= 0.14, < 2.0)
+ listen (3.1.5)
+ rb-fsevent (~> 0.9, >= 0.9.4)
+ rb-inotify (~> 0.9, >= 0.9.7)
+ ruby_dep (~> 1.2)
+ loofah (2.2.3)
+ crass (~> 1.0.2)
+ nokogiri (>= 1.5.9)
+ mail (2.7.1)
+ mini_mime (>= 0.1.1)
+ marcel (0.3.3)
+ mimemagic (~> 0.3.2)
+ method_source (0.9.2)
+ mimemagic (0.3.2)
+ mini_mime (1.0.1)
+ mini_portile2 (2.4.0)
+ minitest (5.11.3)
+ msgpack (1.2.4)
+ multi_json (1.13.1)
+ nio4r (2.3.1)
+ nokogiri (1.9.1)
+ mini_portile2 (~> 2.4.0)
+ pg (1.1.3)
+ popper_js (1.14.5)
+ pry (0.12.2)
+ coderay (~> 1.1.0)
+ method_source (~> 0.9.0)
+ pry-rails (0.3.8)
+ pry (>= 0.10.4)
+ puma (3.12.0)
+ rack (2.0.6)
+ rack-test (1.1.0)
+ rack (>= 1.0, < 3)
+ rails (5.2.2)
+ actioncable (= 5.2.2)
+ actionmailer (= 5.2.2)
+ actionpack (= 5.2.2)
+ actionview (= 5.2.2)
+ activejob (= 5.2.2)
+ activemodel (= 5.2.2)
+ activerecord (= 5.2.2)
+ activestorage (= 5.2.2)
+ activesupport (= 5.2.2)
+ bundler (>= 1.3.0)
+ railties (= 5.2.2)
+ sprockets-rails (>= 2.0.0)
+ rails-dom-testing (2.0.3)
+ activesupport (>= 4.2.0)
+ nokogiri (>= 1.6)
+ rails-html-sanitizer (1.0.4)
+ loofah (~> 2.2, >= 2.2.2)
+ railties (5.2.2)
+ actionpack (= 5.2.2)
+ activesupport (= 5.2.2)
+ method_source
+ rake (>= 0.8.7)
+ thor (>= 0.19.0, < 2.0)
+ rake (12.3.2)
+ rb-fsevent (0.10.3)
+ rb-inotify (0.10.0)
+ ffi (~> 1.0)
+ ruby_dep (1.5.0)
+ sass (3.7.2)
+ sass-listen (~> 4.0.0)
+ sass-listen (4.0.0)
+ rb-fsevent (~> 0.9, >= 0.9.4)
+ rb-inotify (~> 0.9, >= 0.9.7)
+ sass-rails (5.0.7)
+ railties (>= 4.0.0, < 6)
+ sass (~> 3.1)
+ sprockets (>= 2.8, < 4.0)
+ sprockets-rails (>= 2.0, < 4.0)
+ tilt (>= 1.1, < 3)
+ spring (2.0.2)
+ activesupport (>= 4.2)
+ spring-watcher-listen (2.0.1)
+ listen (>= 2.7, < 4.0)
+ spring (>= 1.2, < 3.0)
+ sprockets (3.7.2)
+ concurrent-ruby (~> 1.0)
+ rack (> 1, < 3)
+ sprockets-rails (3.2.1)
+ actionpack (>= 4.0)
+ activesupport (>= 4.0)
+ sprockets (>= 3.0.0)
+ thor (0.20.3)
+ thread_safe (0.3.6)
+ tilt (2.0.9)
+ tzinfo (1.2.5)
+ thread_safe (~> 0.1)
+ uglifier (4.1.20)
+ execjs (>= 0.3.0, < 3)
+ web-console (3.7.0)
+ actionview (>= 5.0)
+ activemodel (>= 5.0)
+ bindex (>= 0.4.0)
+ railties (>= 5.0)
+ websocket-driver (0.7.0)
+ websocket-extensions (>= 0.1.0)
+ websocket-extensions (0.1.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bcrypt (~> 3.1.7)
+ bootsnap (>= 1.1.0)
+ bootstrap
+ byebug
+ cancancan
+ coffee-rails (~> 4.2)
+ faker
+ hirb
+ jbuilder (~> 2.5)
+ jquery-rails
+ listen (>= 3.0.5, < 3.2)
+ pg (>= 0.18, < 2.0)
+ pry
+ pry-rails
+ puma (~> 3.11)
+ rails (~> 5.2.2)
+ sass-rails (~> 5.0)
+ spring
+ spring-watcher-listen (~> 2.0.0)
+ tzinfo-data
+ uglifier (>= 1.3.0)
+ web-console (>= 3.3.0)
+
+RUBY VERSION
+ ruby 2.5.1p57
+
+BUNDLED WITH
+ 1.17.1
diff --git a/blog_on_rails/README.md b/blog_on_rails/README.md
new file mode 100644
index 0000000..7db80e4
--- /dev/null
+++ b/blog_on_rails/README.md
@@ -0,0 +1,24 @@
+# README
+
+This README would normally document whatever steps are necessary to get the
+application up and running.
+
+Things you may want to cover:
+
+* Ruby version
+
+* System dependencies
+
+* Configuration
+
+* Database creation
+
+* Database initialization
+
+* How to run the test suite
+
+* Services (job queues, cache servers, search engines, etc.)
+
+* Deployment instructions
+
+* ...
diff --git a/blog_on_rails/Rakefile b/blog_on_rails/Rakefile
new file mode 100644
index 0000000..e85f913
--- /dev/null
+++ b/blog_on_rails/Rakefile
@@ -0,0 +1,6 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require_relative 'config/application'
+
+Rails.application.load_tasks
diff --git a/blog_on_rails/app/assets/config/manifest.js b/blog_on_rails/app/assets/config/manifest.js
new file mode 100644
index 0000000..b16e53d
--- /dev/null
+++ b/blog_on_rails/app/assets/config/manifest.js
@@ -0,0 +1,3 @@
+//= link_tree ../images
+//= link_directory ../javascripts .js
+//= link_directory ../stylesheets .css
diff --git a/blog_on_rails/app/assets/images/.keep b/blog_on_rails/app/assets/images/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/blog_on_rails/app/assets/javascripts/application.js b/blog_on_rails/app/assets/javascripts/application.js
new file mode 100644
index 0000000..be276fb
--- /dev/null
+++ b/blog_on_rails/app/assets/javascripts/application.js
@@ -0,0 +1,18 @@
+// This is a manifest file that'll be compiled into application.js, which will include all the files
+// listed below.
+//
+// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
+// vendor/assets/javascripts directory can be referenced here using a relative path.
+//
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// compiled file. JavaScript code in this file should be added after the last require_* statement.
+//
+// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
+// about supported directives.
+//
+//= require jquery3
+//= require popper
+//= require bootstrap
+//= require rails-ujs
+//= require activestorage
+//= require_tree .
diff --git a/blog_on_rails/app/assets/javascripts/cable.js b/blog_on_rails/app/assets/javascripts/cable.js
new file mode 100644
index 0000000..739aa5f
--- /dev/null
+++ b/blog_on_rails/app/assets/javascripts/cable.js
@@ -0,0 +1,13 @@
+// Action Cable provides the framework to deal with WebSockets in Rails.
+// You can generate new channels where WebSocket features live using the `rails generate channel` command.
+//
+//= require action_cable
+//= require_self
+//= require_tree ./channels
+
+(function() {
+ this.App || (this.App = {});
+
+ App.cable = ActionCable.createConsumer();
+
+}).call(this);
diff --git a/blog_on_rails/app/assets/javascripts/channels/.keep b/blog_on_rails/app/assets/javascripts/channels/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/blog_on_rails/app/assets/stylesheets/application.scss b/blog_on_rails/app/assets/stylesheets/application.scss
new file mode 100644
index 0000000..6e272c1
--- /dev/null
+++ b/blog_on_rails/app/assets/stylesheets/application.scss
@@ -0,0 +1,18 @@
+/*
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
+ * listed below.
+ *
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
+ * vendor/assets/stylesheets directory can be referenced here using a relative path.
+ *
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
+ * files in this directory. Styles in this file should be added after the last require_* statement.
+ * It is generally better to create a new file per style scope.
+ *
+ *
+ */
+
+ @import 'bootstrap';
+ @import 'main';
+
\ No newline at end of file
diff --git a/blog_on_rails/app/assets/stylesheets/main.scss b/blog_on_rails/app/assets/stylesheets/main.scss
new file mode 100644
index 0000000..d94a96d
--- /dev/null
+++ b/blog_on_rails/app/assets/stylesheets/main.scss
@@ -0,0 +1,5 @@
+.box {
+
+ border: 10px
+
+}
\ No newline at end of file
diff --git a/blog_on_rails/app/channels/application_cable/channel.rb b/blog_on_rails/app/channels/application_cable/channel.rb
new file mode 100644
index 0000000..d672697
--- /dev/null
+++ b/blog_on_rails/app/channels/application_cable/channel.rb
@@ -0,0 +1,4 @@
+module ApplicationCable
+ class Channel < ActionCable::Channel::Base
+ end
+end
diff --git a/blog_on_rails/app/channels/application_cable/connection.rb b/blog_on_rails/app/channels/application_cable/connection.rb
new file mode 100644
index 0000000..0ff5442
--- /dev/null
+++ b/blog_on_rails/app/channels/application_cable/connection.rb
@@ -0,0 +1,4 @@
+module ApplicationCable
+ class Connection < ActionCable::Connection::Base
+ end
+end
diff --git a/blog_on_rails/app/controllers/application_controller.rb b/blog_on_rails/app/controllers/application_controller.rb
new file mode 100644
index 0000000..6e5fdad
--- /dev/null
+++ b/blog_on_rails/app/controllers/application_controller.rb
@@ -0,0 +1,22 @@
+class ApplicationController < ActionController::Base
+
+ private
+ def current_user
+ if session[:user_id].present?
+ @current_user ||= User.find_by(id: session[:user_id])
+ end
+ end
+ helper_method(:current_user)
+
+ def user_signed_in?
+ current_user.present?
+ end
+ helper_method(:user_signed_in?)
+
+ def authenticate_user!
+ unless user_signed_in?
+ flash[:danger] = "You must sign in or sign up"
+ redirect_to new_session_path
+ end
+ end
+end
diff --git a/blog_on_rails/app/controllers/comments_controller.rb b/blog_on_rails/app/controllers/comments_controller.rb
new file mode 100644
index 0000000..635436f
--- /dev/null
+++ b/blog_on_rails/app/controllers/comments_controller.rb
@@ -0,0 +1,40 @@
+class CommentsController < ApplicationController
+ before_action :authenticate_user!
+ before_action :authorized_user!, only: [:destroy]
+
+ def destroy
+ @comment = Comment.find params[:id]
+ @comment.destroy
+ flash[:primary] = "We're sad to see that you deleted your comment."
+ redirect_to post_path(@comment.post)
+ end
+
+ def create
+ @comment = Comment.new comment_params
+ @post = Post.find params[:id]
+ @comment.post = @post
+ @comment.user = current_user
+
+ if @comment.save
+ flash[:primary] = "Thanks for your comment!"
+ redirect_to post_path(@post.id)
+ else
+ @comments = @post.comments.order(created_at: :desc)
+ render "posts/show"
+ end
+ end
+
+ private
+ def comment_params
+ params.require(:comment).permit(:body)
+ end
+
+ def authorized_user!
+ @comment = Comment.find params[:id]
+ unless can?(:crud, @comment)
+ flash[:danger] = "You are not authorized!"
+ redirect_to post_path(@comment.post)
+ end
+ end
+end
+
diff --git a/blog_on_rails/app/controllers/concerns/.keep b/blog_on_rails/app/controllers/concerns/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/blog_on_rails/app/controllers/posts_controller.rb b/blog_on_rails/app/controllers/posts_controller.rb
new file mode 100644
index 0000000..494232a
--- /dev/null
+++ b/blog_on_rails/app/controllers/posts_controller.rb
@@ -0,0 +1,64 @@
+class PostsController < ApplicationController
+ before_action :authenticate_user!, except: [:show, :index]
+ before_action :authorized_user!, only: [:edit, :update, :destroy]
+
+ def index
+ @posts = Post.all.order(created_at: :desc)
+ end
+
+ def show
+ @post = Post.find params[:id]
+ @comments = @post.comments.order(created_at: :desc)
+ @comment = Comment.new
+ end
+
+ def new
+ @post = Post.new
+ end
+
+ def create
+ @post = Post.new post_params
+ @post.user = current_user
+ if @post.save
+ flash[:primary] = "Thanks for your new post!"
+ redirect_to post_path(@post.id)
+ else
+ render :new
+ end
+ end
+
+ def edit
+ @post = Post.find params[:id]
+ end
+
+ def update
+ @post = Post.find params[:id]
+ if @post.update post_params
+ flash[:primary] = "Thanks for updating your post!"
+ redirect_to post_path(@post.id)
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @post = Post.find params[:id]
+ @post.destroy
+ flash[:primary] = "We're sorry to see that you deleted your post."
+ redirect_to root_path
+ end
+
+ private
+
+ def post_params
+ params.require(:post).permit(:title, :body)
+ end
+
+ def authorized_user!
+ @post = Post.find params[:id]
+ unless can?(:crud, @post)
+ flash[:danger] = "You are not authorized!"
+ redirect_to post_path("#{@post.id}")
+ end
+ end
+end
diff --git a/blog_on_rails/app/controllers/sessions_controller.rb b/blog_on_rails/app/controllers/sessions_controller.rb
new file mode 100644
index 0000000..86d3545
--- /dev/null
+++ b/blog_on_rails/app/controllers/sessions_controller.rb
@@ -0,0 +1,23 @@
+class SessionsController < ApplicationController
+ def new
+ end
+
+ def create
+ user = User.find_by_email params[:email]
+ if user&.authenticate(params[:password])
+ session[:user_id] = user.id
+ flash[:success] = "Welcome #{user.name}."
+ redirect_to root_path
+ else
+ flash[:danger] = "Password or Email incorrect"
+ render :new
+ end
+ end
+
+ def destroy
+ user = User.find_by_id(session[:user_id])
+ session[:user_id] = nil
+ flash[:primary] = "See you next time, #{user.name}."
+ redirect_to root_path
+ end
+end
diff --git a/blog_on_rails/app/controllers/users_controller.rb b/blog_on_rails/app/controllers/users_controller.rb
new file mode 100644
index 0000000..cfd7eb5
--- /dev/null
+++ b/blog_on_rails/app/controllers/users_controller.rb
@@ -0,0 +1,69 @@
+class UsersController < ApplicationController
+ before_action :authenticate_user!, only: [:edit, :update]
+ before_action :authorized_user!, only: [:edit, :update]
+
+ def new
+ @user = User.new
+ end
+
+ def create
+ @user = User.new user_params
+ if @user.save
+ flash[:primary] = "Welcome, #{@user.name}!"
+ session[:user_id] = @user.id
+ redirect_to root_path
+ else
+ render :new
+ end
+ end
+
+ def edit
+ @user = User.find params[:id]
+ end
+
+ def update
+ @user = User.find params[:id]
+ if @user.update user_params
+ redirect_to root_path
+ else
+ render :edit
+ end
+ end
+
+ def edit_password
+ @user = User.find params[:id]
+ end
+
+ def update_password
+ @user = User.find params[:id]
+ old_password = password_params[:old_password]
+ new_password = password_params[:new_password]
+ new_password_confirmation = password_params[:new_password_confirmation]
+
+ if old_password != new_password && new_password == new_password_confirmation
+ @user.password = password_params[:new_password]
+ @user.save
+ redirect_to root_path
+ else
+ render :edit_password
+ end
+ end
+
+ private
+
+ def user_params
+ params.require(:user).permit(:name, :email, :password, :password_confirmation)
+ end
+
+ def password_params
+ params.permit(:old_password, :new_password, :new_password_confirmation)
+ end
+
+ def authorized_user!
+ @user = User.find params[:id]
+ unless can?(:crud, @user)
+ flash[:danger] = "you are NOT authorized!"
+ redirect_to root_path
+ end
+ end
+end
diff --git a/blog_on_rails/app/helpers/application_helper.rb b/blog_on_rails/app/helpers/application_helper.rb
new file mode 100644
index 0000000..de6be79
--- /dev/null
+++ b/blog_on_rails/app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
diff --git a/blog_on_rails/app/jobs/application_job.rb b/blog_on_rails/app/jobs/application_job.rb
new file mode 100644
index 0000000..a009ace
--- /dev/null
+++ b/blog_on_rails/app/jobs/application_job.rb
@@ -0,0 +1,2 @@
+class ApplicationJob < ActiveJob::Base
+end
diff --git a/blog_on_rails/app/mailers/application_mailer.rb b/blog_on_rails/app/mailers/application_mailer.rb
new file mode 100644
index 0000000..286b223
--- /dev/null
+++ b/blog_on_rails/app/mailers/application_mailer.rb
@@ -0,0 +1,4 @@
+class ApplicationMailer < ActionMailer::Base
+ default from: 'from@example.com'
+ layout 'mailer'
+end
diff --git a/blog_on_rails/app/models/ability.rb b/blog_on_rails/app/models/ability.rb
new file mode 100644
index 0000000..24d225e
--- /dev/null
+++ b/blog_on_rails/app/models/ability.rb
@@ -0,0 +1,46 @@
+class Ability
+ include CanCan::Ability
+
+ def initialize(user)
+ # Define abilities for the passed in user here. For example:
+ #
+ user ||= User.new # guest user (not logged in)
+ if user.admin?
+ can :manage, :all
+ else
+ can :read, :all
+ end
+ #
+ # The first argument to `can` is the action you are giving the user
+ # permission to do.
+ # If you pass :manage it will apply to every action. Other common actions
+ # here are :read, :create, :update and :destroy.
+ #
+ # The second argument is the resource the user can perform the action on.
+ # If you pass :all it will apply to every resource. Otherwise pass a Ruby
+ # class of the resource.
+ #
+ # The third argument is an optional hash of conditions to further filter the
+ # objects.
+ # For example, here the user can only update published articles.
+ #
+ # can :update, Article, :published => true
+ #
+ # See the wiki for details:
+ # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
+ alias_action(:create, :read, :edit, :update, :delete, :update_password, to: :crud)
+
+ can(:crud, Post) do |post|
+ post.user == user
+ end
+
+ can(:crud, Comment) do |comment|
+ comment.user == user
+ end
+
+ can(:crud, User) do |correct_user|
+ correct_user == user
+ end
+
+ end
+end
diff --git a/blog_on_rails/app/models/application_record.rb b/blog_on_rails/app/models/application_record.rb
new file mode 100644
index 0000000..10a4cba
--- /dev/null
+++ b/blog_on_rails/app/models/application_record.rb
@@ -0,0 +1,3 @@
+class ApplicationRecord < ActiveRecord::Base
+ self.abstract_class = true
+end
diff --git a/blog_on_rails/app/models/comment.rb b/blog_on_rails/app/models/comment.rb
new file mode 100644
index 0000000..2a92545
--- /dev/null
+++ b/blog_on_rails/app/models/comment.rb
@@ -0,0 +1,8 @@
+class Comment < ApplicationRecord
+ belongs_to :post
+ belongs_to :user
+
+ validates(
+ :body, presence: true
+ )
+end
diff --git a/blog_on_rails/app/models/concerns/.keep b/blog_on_rails/app/models/concerns/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/blog_on_rails/app/models/post.rb b/blog_on_rails/app/models/post.rb
new file mode 100644
index 0000000..4c281a1
--- /dev/null
+++ b/blog_on_rails/app/models/post.rb
@@ -0,0 +1,17 @@
+class Post < ApplicationRecord
+ has_many(:comments, dependent: :destroy)
+ belongs_to :user
+
+ validates(
+ :title,
+ presence: true,
+ uniqueness: true
+ )
+
+ validates(
+ :body,
+ presence: true,
+ length: { minimum: 50 }
+ )
+
+end
diff --git a/blog_on_rails/app/models/user.rb b/blog_on_rails/app/models/user.rb
new file mode 100644
index 0000000..c719de9
--- /dev/null
+++ b/blog_on_rails/app/models/user.rb
@@ -0,0 +1,10 @@
+class User < ApplicationRecord
+ has_many(:posts, dependent: :nullify)
+ has_many(:comments, dependent: :nullify)
+
+ has_secure_password
+
+ validates :email, presence: true,
+ uniqueness: true,
+ format: /\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
+end
diff --git a/blog_on_rails/app/views/layouts/application.html.erb b/blog_on_rails/app/views/layouts/application.html.erb
new file mode 100644
index 0000000..9f2073f
--- /dev/null
+++ b/blog_on_rails/app/views/layouts/application.html.erb
@@ -0,0 +1,64 @@
+
+
+
+ BlogOnRails
+ <%= csrf_meta_tags %>
+ <%= csp_meta_tag %>
+
+ <%= stylesheet_link_tag 'application', media: 'all' %>
+ <%= javascript_include_tag 'application' %>
+
+
+
+
+
+ <% flash.each do |type, message|%>
+
+ <%= message %>
+
+ <% end %>
+
+
+ <%= yield %>
+
+
diff --git a/blog_on_rails/app/views/layouts/mailer.html.erb b/blog_on_rails/app/views/layouts/mailer.html.erb
new file mode 100644
index 0000000..cbd34d2
--- /dev/null
+++ b/blog_on_rails/app/views/layouts/mailer.html.erb
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+ <%= yield %>
+
+
diff --git a/blog_on_rails/app/views/layouts/mailer.text.erb b/blog_on_rails/app/views/layouts/mailer.text.erb
new file mode 100644
index 0000000..37f0bdd
--- /dev/null
+++ b/blog_on_rails/app/views/layouts/mailer.text.erb
@@ -0,0 +1 @@
+<%= yield %>
diff --git a/blog_on_rails/app/views/posts/edit.html.erb b/blog_on_rails/app/views/posts/edit.html.erb
new file mode 100644
index 0000000..b782094
--- /dev/null
+++ b/blog_on_rails/app/views/posts/edit.html.erb
@@ -0,0 +1,21 @@
+
+ <%= form_with(model: @post, local: true) do |form| %>
+ <% if @post.errors.present? %>
+
+ <%= @post.errors.full_messages.join(", ") %>
+
+ <% end %>
+
+ <%= form.label :title%>
+ <%= form.text_field :title, class: "form-control"%>
+
+
+
+ <%= form.label :body%>
+ <%= form.text_area :body, class: "form-control"%>
+
+ <%= form.submit "Update Post", class: "btn btn-outline-primary"%>
+ <% end %>
+
+
+
\ No newline at end of file
diff --git a/blog_on_rails/app/views/posts/index.html.erb b/blog_on_rails/app/views/posts/index.html.erb
new file mode 100644
index 0000000..94bfa48
--- /dev/null
+++ b/blog_on_rails/app/views/posts/index.html.erb
@@ -0,0 +1,15 @@
+
+
+ <% @posts.each do |post|%>
+
+
+
<%= link_to(post.title, "/posts/#{post.id}")%>
+
<%=post.body%>
+
Posted <%= time_ago_in_words(post.created_at)%> ago
+
+
+ <%end%>
+
+
+
+
diff --git a/blog_on_rails/app/views/posts/new.html.erb b/blog_on_rails/app/views/posts/new.html.erb
new file mode 100644
index 0000000..fe9a5fb
--- /dev/null
+++ b/blog_on_rails/app/views/posts/new.html.erb
@@ -0,0 +1,21 @@
+
+ <%= form_with(model: @post, local: true) do |form| %>
+ <% if @post.errors.present? %>
+
+ <%= @post.errors.full_messages.join(", ") %>
+
+ <% end %>
+
+ <%= form.label :title%>
+ <%= form.text_field :title, class: "form-control"%>
+
+
+
+ <%= form.label :body%>
+ <%= form.text_area :body, class: "form-control"%>
+
+ <%= form.submit "Create Post", class: "btn btn-outline-primary"%>
+ <% end %>
+
+
+
\ No newline at end of file
diff --git a/blog_on_rails/app/views/posts/show.html.erb b/blog_on_rails/app/views/posts/show.html.erb
new file mode 100644
index 0000000..efd2e5d
--- /dev/null
+++ b/blog_on_rails/app/views/posts/show.html.erb
@@ -0,0 +1,44 @@
+
+
<%=@post.title%>
+
<%=@post.body%>
+
<%=@post.user.name%> posted <%= time_ago_in_words(@post.created_at)%> ago
+ <% if can?(:crud, @post)%>
+
+
+ <%= link_to("Edit Post", "/posts/#{@post.id}/edit")%>
+
+
+ <%= link_to("Delete Post", post_path(@post.id), method: :delete, data: {confirm: "Are you sure?"})%>
+
+
+ <% end %>
+
+
+<% if user_signed_in? %>
+
+ <%= form_with(model: [@post, @comment], local: true) do |form| %>
+
+ <%= form.label :Comment%>
+ <%= form.text_area :body, class: "form-control"%>
+
+ <%= form.submit "Submit", class: "btn btn-outline-primary"%>
+ <% end %>
+
+<% end %>
+
+
+<% @comments.each do |comment|%>
+
<%= comment.body%>
+
<%=comment.user.name%> commented <%= time_ago_in_words(comment.created_at)%> ago
+ <% if can?(:crud, comment)%>
+ ∙
+ <%= link_to("Delete Comment", destroy_comment_path(comment.id), method: :delete, data: {confirm: "Sure?"})%>
+
+ <% end %>
+<% end %>
+
+
+
+
+
+
diff --git a/blog_on_rails/app/views/sessions/new.html.erb b/blog_on_rails/app/views/sessions/new.html.erb
new file mode 100644
index 0000000..11b2495
--- /dev/null
+++ b/blog_on_rails/app/views/sessions/new.html.erb
@@ -0,0 +1,13 @@
+
+<%= form_with(url: new_session_path, local: true) do |form|%>
+
+ <%= form.label :email %>
+ <%= form.text_field :email, class: "form-control" %>
+
+
+ <%= form.label :password %>
+ <%= form.password_field :password, class: "form-control" %>
+
+ <%= form.submit "Log in", class: "btn btn-outline-primary"%>
+<% end %>
+
\ No newline at end of file
diff --git a/blog_on_rails/app/views/users/edit.html.erb b/blog_on_rails/app/views/users/edit.html.erb
new file mode 100644
index 0000000..7f86db7
--- /dev/null
+++ b/blog_on_rails/app/views/users/edit.html.erb
@@ -0,0 +1,14 @@
+
+<%= form_with(model: @user, local: true) do |form|%>
+
+ <%= form.label :name %>
+ <%= form.text_field :name, class: "form-control" %>
+
+
+ <%= form.label :email %>
+ <%= form.text_field :email, class: "form-control" %>
+
+ <%= form.submit "Update", class: "btn btn-outline-primary"%>
+ <%= link_to("Change Password", edit_password_path(@user.id), class: "btn btn-outline-primary")%>
+<% end %>
+
\ No newline at end of file
diff --git a/blog_on_rails/app/views/users/edit_password.html.erb b/blog_on_rails/app/views/users/edit_password.html.erb
new file mode 100644
index 0000000..dc35b41
--- /dev/null
+++ b/blog_on_rails/app/views/users/edit_password.html.erb
@@ -0,0 +1,17 @@
+
+<%= form_with(url: "/users/#{@user.id}/edit/password", local: true) do |form|%>
+
+ <%= form.label :old_password %>
+ <%= form.password_field :old_password, class: "form-control" %>
+
+
+ <%= form.label :new_password %>
+ <%= form.password_field :new_password, class: "form-control" %>
+
+
+ <%= form.label :new_password_confirmation %>
+ <%= form.password_field :new_password_confirmation, class: "form-control" %>
+
+ <%= form.submit "Change Password", class: "btn btn-outline-primary"%>
+<% end %>
+
\ No newline at end of file
diff --git a/blog_on_rails/app/views/users/new.html.erb b/blog_on_rails/app/views/users/new.html.erb
new file mode 100644
index 0000000..f93fdd6
--- /dev/null
+++ b/blog_on_rails/app/views/users/new.html.erb
@@ -0,0 +1,21 @@
+
+<%= form_with(model: @user, local: true) do |form|%>
+
+ <%= form.label :name %>
+ <%= form.text_field :name, class: "form-control" %>
+
+
+ <%= form.label :email %>
+ <%= form.text_field :email, class: "form-control" %>
+
+
+ <%= form.label :password %>
+ <%= form.password_field :password, class: "form-control" %>
+
+
+ <%= form.label :password_confirmation %>
+ <%= form.password_field :password_confirmation, class: "form-control" %>
+
+ <%= form.submit "Sign Up", class: "btn btn-outline-primary"%>
+<% end %>
+
\ No newline at end of file
diff --git a/blog_on_rails/bin/bundle b/blog_on_rails/bin/bundle
new file mode 100755
index 0000000..f19acf5
--- /dev/null
+++ b/blog_on_rails/bin/bundle
@@ -0,0 +1,3 @@
+#!/usr/bin/env ruby
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
+load Gem.bin_path('bundler', 'bundle')
diff --git a/blog_on_rails/bin/rails b/blog_on_rails/bin/rails
new file mode 100755
index 0000000..5badb2f
--- /dev/null
+++ b/blog_on_rails/bin/rails
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+begin
+ load File.expand_path('../spring', __FILE__)
+rescue LoadError => e
+ raise unless e.message.include?('spring')
+end
+APP_PATH = File.expand_path('../config/application', __dir__)
+require_relative '../config/boot'
+require 'rails/commands'
diff --git a/blog_on_rails/bin/rake b/blog_on_rails/bin/rake
new file mode 100755
index 0000000..d87d5f5
--- /dev/null
+++ b/blog_on_rails/bin/rake
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+begin
+ load File.expand_path('../spring', __FILE__)
+rescue LoadError => e
+ raise unless e.message.include?('spring')
+end
+require_relative '../config/boot'
+require 'rake'
+Rake.application.run
diff --git a/blog_on_rails/bin/setup b/blog_on_rails/bin/setup
new file mode 100755
index 0000000..94fd4d7
--- /dev/null
+++ b/blog_on_rails/bin/setup
@@ -0,0 +1,36 @@
+#!/usr/bin/env ruby
+require 'fileutils'
+include FileUtils
+
+# path to your application root.
+APP_ROOT = File.expand_path('..', __dir__)
+
+def system!(*args)
+ system(*args) || abort("\n== Command #{args} failed ==")
+end
+
+chdir APP_ROOT do
+ # This script is a starting point to setup your application.
+ # Add necessary setup steps to this file.
+
+ puts '== Installing dependencies =='
+ system! 'gem install bundler --conservative'
+ system('bundle check') || system!('bundle install')
+
+ # Install JavaScript dependencies if using Yarn
+ # system('bin/yarn')
+
+ # puts "\n== Copying sample files =="
+ # unless File.exist?('config/database.yml')
+ # cp 'config/database.yml.sample', 'config/database.yml'
+ # end
+
+ puts "\n== Preparing database =="
+ system! 'bin/rails db:setup'
+
+ puts "\n== Removing old logs and tempfiles =="
+ system! 'bin/rails log:clear tmp:clear'
+
+ puts "\n== Restarting application server =="
+ system! 'bin/rails restart'
+end
diff --git a/blog_on_rails/bin/spring b/blog_on_rails/bin/spring
new file mode 100755
index 0000000..fb2ec2e
--- /dev/null
+++ b/blog_on_rails/bin/spring
@@ -0,0 +1,17 @@
+#!/usr/bin/env ruby
+
+# This file loads spring without using Bundler, in order to be fast.
+# It gets overwritten when you run the `spring binstub` command.
+
+unless defined?(Spring)
+ require 'rubygems'
+ require 'bundler'
+
+ lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
+ spring = lockfile.specs.detect { |spec| spec.name == "spring" }
+ if spring
+ Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
+ gem 'spring', spring.version
+ require 'spring/binstub'
+ end
+end
diff --git a/blog_on_rails/bin/update b/blog_on_rails/bin/update
new file mode 100755
index 0000000..58bfaed
--- /dev/null
+++ b/blog_on_rails/bin/update
@@ -0,0 +1,31 @@
+#!/usr/bin/env ruby
+require 'fileutils'
+include FileUtils
+
+# path to your application root.
+APP_ROOT = File.expand_path('..', __dir__)
+
+def system!(*args)
+ system(*args) || abort("\n== Command #{args} failed ==")
+end
+
+chdir APP_ROOT do
+ # This script is a way to update your development environment automatically.
+ # Add necessary update steps to this file.
+
+ puts '== Installing dependencies =='
+ system! 'gem install bundler --conservative'
+ system('bundle check') || system!('bundle install')
+
+ # Install JavaScript dependencies if using Yarn
+ # system('bin/yarn')
+
+ puts "\n== Updating database =="
+ system! 'bin/rails db:migrate'
+
+ puts "\n== Removing old logs and tempfiles =="
+ system! 'bin/rails log:clear tmp:clear'
+
+ puts "\n== Restarting application server =="
+ system! 'bin/rails restart'
+end
diff --git a/blog_on_rails/bin/yarn b/blog_on_rails/bin/yarn
new file mode 100755
index 0000000..460dd56
--- /dev/null
+++ b/blog_on_rails/bin/yarn
@@ -0,0 +1,11 @@
+#!/usr/bin/env ruby
+APP_ROOT = File.expand_path('..', __dir__)
+Dir.chdir(APP_ROOT) do
+ begin
+ exec "yarnpkg", *ARGV
+ rescue Errno::ENOENT
+ $stderr.puts "Yarn executable was not detected in the system."
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
+ exit 1
+ end
+end
diff --git a/blog_on_rails/config.ru b/blog_on_rails/config.ru
new file mode 100644
index 0000000..f7ba0b5
--- /dev/null
+++ b/blog_on_rails/config.ru
@@ -0,0 +1,5 @@
+# This file is used by Rack-based servers to start the application.
+
+require_relative 'config/environment'
+
+run Rails.application
diff --git a/blog_on_rails/config/application.rb b/blog_on_rails/config/application.rb
new file mode 100644
index 0000000..799b8ae
--- /dev/null
+++ b/blog_on_rails/config/application.rb
@@ -0,0 +1,33 @@
+require_relative 'boot'
+
+require "rails"
+# Pick the frameworks you want:
+require "active_model/railtie"
+require "active_job/railtie"
+require "active_record/railtie"
+require "active_storage/engine"
+require "action_controller/railtie"
+require "action_mailer/railtie"
+require "action_view/railtie"
+require "action_cable/engine"
+require "sprockets/railtie"
+# require "rails/test_unit/railtie"
+
+# Require the gems listed in Gemfile, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(*Rails.groups)
+
+module BlogOnRails
+ class Application < Rails::Application
+ # Initialize configuration defaults for originally generated Rails version.
+ config.load_defaults 5.2
+
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration can go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded after loading
+ # the framework and any gems in your application.
+
+ # Don't generate system test files.
+ config.generators.system_tests = nil
+ end
+end
diff --git a/blog_on_rails/config/boot.rb b/blog_on_rails/config/boot.rb
new file mode 100644
index 0000000..b9e460c
--- /dev/null
+++ b/blog_on_rails/config/boot.rb
@@ -0,0 +1,4 @@
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
+
+require 'bundler/setup' # Set up gems listed in the Gemfile.
+require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
diff --git a/blog_on_rails/config/cable.yml b/blog_on_rails/config/cable.yml
new file mode 100644
index 0000000..7b6ffc4
--- /dev/null
+++ b/blog_on_rails/config/cable.yml
@@ -0,0 +1,10 @@
+development:
+ adapter: async
+
+test:
+ adapter: async
+
+production:
+ adapter: redis
+ url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
+ channel_prefix: blog_on_rails_production
diff --git a/blog_on_rails/config/credentials.yml.enc b/blog_on_rails/config/credentials.yml.enc
new file mode 100644
index 0000000..ae11861
--- /dev/null
+++ b/blog_on_rails/config/credentials.yml.enc
@@ -0,0 +1 @@
+UpvjSMe0mlW8at6+AVHoFnciAaM++V7rqqDFuTI2YtvsEM0+Ma6EvQ33W2TnUIueubzLIVw0ubpErmfpgh7oP7Fr540XdAQALEI0fxin7jhZOJjv3pc/3kfa/S44Hl9vOsSLNBzrQMvaHLpX9ccwGYk6Xskkfy2iAePrkR2RxhbOBoBNRJi0mhL4CffhpAZRpMq4/Bpev1tojLluhQbg4KpkxhNeSYsEjeP5PMc/4VUbE+O/f16oi2ovcb9DtoOJpObndbnd+Lwtq+DQG7HNxxoQlPxJELw+Gb+5QDuu52bBj5dBVZyYdMXTp1LjmgAhPrNuPveqJiEoP22vrYsn6ZdUfeZWj5crwnJz1L34lPXKosuvRBSxox5o0APfOwwNPUxV+apJxmq5WO0JD1+YJrpgFnrt0U0vq2Si--s0VPJObYkrHvgdTC--aADQAWOcs29v9ojoJ0Ld/A==
\ No newline at end of file
diff --git a/blog_on_rails/config/database.yml b/blog_on_rails/config/database.yml
new file mode 100644
index 0000000..3f99218
--- /dev/null
+++ b/blog_on_rails/config/database.yml
@@ -0,0 +1,85 @@
+# PostgreSQL. Versions 9.1 and up are supported.
+#
+# Install the pg driver:
+# gem install pg
+# On OS X with Homebrew:
+# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
+# On OS X with MacPorts:
+# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
+# On Windows:
+# gem install pg
+# Choose the win32 build.
+# Install PostgreSQL and put its /bin directory on your path.
+#
+# Configure Using Gemfile
+# gem 'pg'
+#
+default: &default
+ adapter: postgresql
+ encoding: unicode
+ # For details on connection pooling, see Rails configuration guide
+ # http://guides.rubyonrails.org/configuring.html#database-pooling
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
+
+development:
+ <<: *default
+ database: blog_on_rails_development
+
+ # The specified database role being used to connect to postgres.
+ # To create additional roles in postgres see `$ createuser --help`.
+ # When left blank, postgres will use the default role. This is
+ # the same name as the operating system user that initialized the database.
+ #username: blog_on_rails
+
+ # The password associated with the postgres role (username).
+ #password:
+
+ # Connect on a TCP socket. Omitted by default since the client uses a
+ # domain socket that doesn't need configuration. Windows does not have
+ # domain sockets, so uncomment these lines.
+ #host: localhost
+
+ # The TCP port the server listens on. Defaults to 5432.
+ # If your server runs on a different port number, change accordingly.
+ #port: 5432
+
+ # Schema search path. The server defaults to $user,public
+ #schema_search_path: myapp,sharedapp,public
+
+ # Minimum log levels, in increasing order:
+ # debug5, debug4, debug3, debug2, debug1,
+ # log, notice, warning, error, fatal, and panic
+ # Defaults to warning.
+ #min_messages: notice
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ <<: *default
+ database: blog_on_rails_test
+
+# As with config/secrets.yml, you never want to store sensitive information,
+# like your database password, in your source code. If your source code is
+# ever seen by anyone, they now have access to your database.
+#
+# Instead, provide the password as a unix environment variable when you boot
+# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
+# for a full rundown on how to provide these environment variables in a
+# production deployment.
+#
+# On Heroku and other platform providers, you may have a full connection URL
+# available as an environment variable. For example:
+#
+# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
+#
+# You can use this database configuration with:
+#
+# production:
+# url: <%= ENV['DATABASE_URL'] %>
+#
+production:
+ <<: *default
+ database: blog_on_rails_production
+ username: blog_on_rails
+ password: <%= ENV['BLOG_ON_RAILS_DATABASE_PASSWORD'] %>
diff --git a/blog_on_rails/config/environment.rb b/blog_on_rails/config/environment.rb
new file mode 100644
index 0000000..426333b
--- /dev/null
+++ b/blog_on_rails/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the Rails application.
+require_relative 'application'
+
+# Initialize the Rails application.
+Rails.application.initialize!
diff --git a/blog_on_rails/config/environments/development.rb b/blog_on_rails/config/environments/development.rb
new file mode 100644
index 0000000..1311e3e
--- /dev/null
+++ b/blog_on_rails/config/environments/development.rb
@@ -0,0 +1,61 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the web server when you make code changes.
+ config.cache_classes = false
+
+ # Do not eager load code on boot.
+ config.eager_load = false
+
+ # Show full error reports.
+ config.consider_all_requests_local = true
+
+ # Enable/disable caching. By default caching is disabled.
+ # Run rails dev:cache to toggle caching.
+ if Rails.root.join('tmp', 'caching-dev.txt').exist?
+ config.action_controller.perform_caching = true
+
+ config.cache_store = :memory_store
+ config.public_file_server.headers = {
+ 'Cache-Control' => "public, max-age=#{2.days.to_i}"
+ }
+ else
+ config.action_controller.perform_caching = false
+
+ config.cache_store = :null_store
+ end
+
+ # Store uploaded files on the local file system (see config/storage.yml for options)
+ config.active_storage.service = :local
+
+ # Don't care if the mailer can't send.
+ config.action_mailer.raise_delivery_errors = false
+
+ config.action_mailer.perform_caching = false
+
+ # Print deprecation notices to the Rails logger.
+ config.active_support.deprecation = :log
+
+ # Raise an error on page load if there are pending migrations.
+ config.active_record.migration_error = :page_load
+
+ # Highlight code that triggered database queries in logs.
+ config.active_record.verbose_query_logs = true
+
+ # Debug mode disables concatenation and preprocessing of assets.
+ # This option may cause significant delays in view rendering with a large
+ # number of complex assets.
+ config.assets.debug = true
+
+ # Suppress logger output for asset requests.
+ config.assets.quiet = true
+
+ # Raises error for missing translations
+ # config.action_view.raise_on_missing_translations = true
+
+ # Use an evented file watcher to asynchronously detect changes in source code,
+ # routes, locales, etc. This feature depends on the listen gem.
+ config.file_watcher = ActiveSupport::EventedFileUpdateChecker
+end
diff --git a/blog_on_rails/config/environments/production.rb b/blog_on_rails/config/environments/production.rb
new file mode 100644
index 0000000..e001007
--- /dev/null
+++ b/blog_on_rails/config/environments/production.rb
@@ -0,0 +1,94 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # Code is not reloaded between requests.
+ config.cache_classes = true
+
+ # Eager load code on boot. This eager loads most of Rails and
+ # your application in memory, allowing both threaded web servers
+ # and those relying on copy on write to perform better.
+ # Rake tasks automatically ignore this option for performance.
+ config.eager_load = true
+
+ # Full error reports are disabled and caching is turned on.
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
+ # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
+ # config.require_master_key = true
+
+ # Disable serving static files from the `/public` folder by default since
+ # Apache or NGINX already handles this.
+ config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
+
+ # Compress JavaScripts and CSS.
+ config.assets.js_compressor = :uglifier
+ # config.assets.css_compressor = :sass
+
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
+ config.assets.compile = false
+
+ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
+
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
+ # config.action_controller.asset_host = 'http://assets.example.com'
+
+ # Specifies the header that your server uses for sending files.
+ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
+
+ # Store uploaded files on the local file system (see config/storage.yml for options)
+ config.active_storage.service = :local
+
+ # Mount Action Cable outside main process or domain
+ # config.action_cable.mount_path = nil
+ # config.action_cable.url = 'wss://example.com/cable'
+ # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
+
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
+ # config.force_ssl = true
+
+ # Use the lowest log level to ensure availability of diagnostic information
+ # when problems arise.
+ config.log_level = :debug
+
+ # Prepend all log lines with the following tags.
+ config.log_tags = [ :request_id ]
+
+ # Use a different cache store in production.
+ # config.cache_store = :mem_cache_store
+
+ # Use a real queuing backend for Active Job (and separate queues per environment)
+ # config.active_job.queue_adapter = :resque
+ # config.active_job.queue_name_prefix = "blog_on_rails_#{Rails.env}"
+
+ config.action_mailer.perform_caching = false
+
+ # Ignore bad email addresses and do not raise email delivery errors.
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation cannot be found).
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners.
+ config.active_support.deprecation = :notify
+
+ # Use default logging formatter so that PID and timestamp are not suppressed.
+ config.log_formatter = ::Logger::Formatter.new
+
+ # Use a different logger for distributed setups.
+ # require 'syslog/logger'
+ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
+
+ if ENV["RAILS_LOG_TO_STDOUT"].present?
+ logger = ActiveSupport::Logger.new(STDOUT)
+ logger.formatter = config.log_formatter
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
+ end
+
+ # Do not dump schema after migrations.
+ config.active_record.dump_schema_after_migration = false
+end
diff --git a/blog_on_rails/config/environments/test.rb b/blog_on_rails/config/environments/test.rb
new file mode 100644
index 0000000..0a38fd3
--- /dev/null
+++ b/blog_on_rails/config/environments/test.rb
@@ -0,0 +1,46 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
+
+ # Do not eager load code on boot. This avoids loading your whole application
+ # just for the purpose of running a single test. If you are using a tool that
+ # preloads Rails for running tests, you may have to set it to true.
+ config.eager_load = false
+
+ # Configure public file server for tests with Cache-Control for performance.
+ config.public_file_server.enabled = true
+ config.public_file_server.headers = {
+ 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
+ }
+
+ # Show full error reports and disable caching.
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates.
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment.
+ config.action_controller.allow_forgery_protection = false
+
+ # Store uploaded files on the local file system in a temporary directory
+ config.active_storage.service = :test
+
+ config.action_mailer.perform_caching = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Print deprecation notices to the stderr.
+ config.active_support.deprecation = :stderr
+
+ # Raises error for missing translations
+ # config.action_view.raise_on_missing_translations = true
+end
diff --git a/blog_on_rails/config/initializers/application_controller_renderer.rb b/blog_on_rails/config/initializers/application_controller_renderer.rb
new file mode 100644
index 0000000..89d2efa
--- /dev/null
+++ b/blog_on_rails/config/initializers/application_controller_renderer.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+# ActiveSupport::Reloader.to_prepare do
+# ApplicationController.renderer.defaults.merge!(
+# http_host: 'example.org',
+# https: false
+# )
+# end
diff --git a/blog_on_rails/config/initializers/assets.rb b/blog_on_rails/config/initializers/assets.rb
new file mode 100644
index 0000000..4b828e8
--- /dev/null
+++ b/blog_on_rails/config/initializers/assets.rb
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+
+# Version of your assets, change this if you want to expire all your assets.
+Rails.application.config.assets.version = '1.0'
+
+# Add additional assets to the asset load path.
+# Rails.application.config.assets.paths << Emoji.images_path
+# Add Yarn node_modules folder to the asset load path.
+Rails.application.config.assets.paths << Rails.root.join('node_modules')
+
+# Precompile additional assets.
+# application.js, application.css, and all non-JS/CSS in the app/assets
+# folder are already added.
+# Rails.application.config.assets.precompile += %w( admin.js admin.css )
diff --git a/blog_on_rails/config/initializers/backtrace_silencers.rb b/blog_on_rails/config/initializers/backtrace_silencers.rb
new file mode 100644
index 0000000..59385cd
--- /dev/null
+++ b/blog_on_rails/config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
diff --git a/blog_on_rails/config/initializers/content_security_policy.rb b/blog_on_rails/config/initializers/content_security_policy.rb
new file mode 100644
index 0000000..d3bcaa5
--- /dev/null
+++ b/blog_on_rails/config/initializers/content_security_policy.rb
@@ -0,0 +1,25 @@
+# Be sure to restart your server when you modify this file.
+
+# Define an application-wide content security policy
+# For further information see the following documentation
+# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
+
+# Rails.application.config.content_security_policy do |policy|
+# policy.default_src :self, :https
+# policy.font_src :self, :https, :data
+# policy.img_src :self, :https, :data
+# policy.object_src :none
+# policy.script_src :self, :https
+# policy.style_src :self, :https
+
+# # Specify URI for violation reports
+# # policy.report_uri "/csp-violation-report-endpoint"
+# end
+
+# If you are using UJS then enable automatic nonce generation
+# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
+
+# Report CSP violations to a specified URI
+# For further information see the following documentation:
+# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
+# Rails.application.config.content_security_policy_report_only = true
diff --git a/blog_on_rails/config/initializers/cookies_serializer.rb b/blog_on_rails/config/initializers/cookies_serializer.rb
new file mode 100644
index 0000000..5a6a32d
--- /dev/null
+++ b/blog_on_rails/config/initializers/cookies_serializer.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Specify a serializer for the signed and encrypted cookie jars.
+# Valid options are :json, :marshal, and :hybrid.
+Rails.application.config.action_dispatch.cookies_serializer = :json
diff --git a/blog_on_rails/config/initializers/filter_parameter_logging.rb b/blog_on_rails/config/initializers/filter_parameter_logging.rb
new file mode 100644
index 0000000..4a994e1
--- /dev/null
+++ b/blog_on_rails/config/initializers/filter_parameter_logging.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Configure sensitive parameters which will be filtered from the log file.
+Rails.application.config.filter_parameters += [:password]
diff --git a/blog_on_rails/config/initializers/inflections.rb b/blog_on_rails/config/initializers/inflections.rb
new file mode 100644
index 0000000..ac033bf
--- /dev/null
+++ b/blog_on_rails/config/initializers/inflections.rb
@@ -0,0 +1,16 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format. Inflections
+# are locale specific, and you may define rules for as many different
+# locales as you wish. All of these examples are active by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
+
+# These inflection rules are supported but not enabled by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.acronym 'RESTful'
+# end
diff --git a/blog_on_rails/config/initializers/mime_types.rb b/blog_on_rails/config/initializers/mime_types.rb
new file mode 100644
index 0000000..dc18996
--- /dev/null
+++ b/blog_on_rails/config/initializers/mime_types.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
diff --git a/blog_on_rails/config/initializers/wrap_parameters.rb b/blog_on_rails/config/initializers/wrap_parameters.rb
new file mode 100644
index 0000000..bbfc396
--- /dev/null
+++ b/blog_on_rails/config/initializers/wrap_parameters.rb
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+
+# This file contains settings for ActionController::ParamsWrapper which
+# is enabled by default.
+
+# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
+ActiveSupport.on_load(:action_controller) do
+ wrap_parameters format: [:json]
+end
+
+# To enable root element in JSON for ActiveRecord objects.
+# ActiveSupport.on_load(:active_record) do
+# self.include_root_in_json = true
+# end
diff --git a/blog_on_rails/config/locales/en.yml b/blog_on_rails/config/locales/en.yml
new file mode 100644
index 0000000..decc5a8
--- /dev/null
+++ b/blog_on_rails/config/locales/en.yml
@@ -0,0 +1,33 @@
+# Files in the config/locales directory are used for internationalization
+# and are automatically loaded by Rails. If you want to use locales other
+# than English, add the necessary files in this directory.
+#
+# To use the locales, use `I18n.t`:
+#
+# I18n.t 'hello'
+#
+# In views, this is aliased to just `t`:
+#
+# <%= t('hello') %>
+#
+# To use a different locale, set it with `I18n.locale`:
+#
+# I18n.locale = :es
+#
+# This would use the information in config/locales/es.yml.
+#
+# The following keys must be escaped otherwise they will not be retrieved by
+# the default I18n backend:
+#
+# true, false, on, off, yes, no
+#
+# Instead, surround them with single quotes.
+#
+# en:
+# 'true': 'foo'
+#
+# To learn more, please read the Rails Internationalization guide
+# available at http://guides.rubyonrails.org/i18n.html.
+
+en:
+ hello: "Hello world"
diff --git a/blog_on_rails/config/puma.rb b/blog_on_rails/config/puma.rb
new file mode 100644
index 0000000..a5eccf8
--- /dev/null
+++ b/blog_on_rails/config/puma.rb
@@ -0,0 +1,34 @@
+# Puma can serve each request in a thread from an internal thread pool.
+# The `threads` method setting takes two numbers: a minimum and maximum.
+# Any libraries that use thread pools should be configured to match
+# the maximum value specified for Puma. Default is set to 5 threads for minimum
+# and maximum; this matches the default thread size of Active Record.
+#
+threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
+threads threads_count, threads_count
+
+# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
+#
+port ENV.fetch("PORT") { 3000 }
+
+# Specifies the `environment` that Puma will run in.
+#
+environment ENV.fetch("RAILS_ENV") { "development" }
+
+# Specifies the number of `workers` to boot in clustered mode.
+# Workers are forked webserver processes. If using threads and workers together
+# the concurrency of the application would be max `threads` * `workers`.
+# Workers do not work on JRuby or Windows (both of which do not support
+# processes).
+#
+# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
+
+# Use the `preload_app!` method when specifying a `workers` number.
+# This directive tells Puma to first boot the application and load code
+# before forking the application. This takes advantage of Copy On Write
+# process behavior so workers use less memory.
+#
+# preload_app!
+
+# Allow puma to be restarted by `rails restart` command.
+plugin :tmp_restart
diff --git a/blog_on_rails/config/routes.rb b/blog_on_rails/config/routes.rb
new file mode 100644
index 0000000..9dd41d6
--- /dev/null
+++ b/blog_on_rails/config/routes.rb
@@ -0,0 +1,38 @@
+Rails.application.routes.draw do
+ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
+
+########################
+# POSTS-related routes #
+########################
+get("/", to: "posts#index", as: :root)
+get("/posts/new", to: "posts#new", as: :new_post)
+post("/posts", to: "posts#create", as: :posts)
+get("/posts/:id", to: "posts#show", as: :post)
+get("/posts/:id/edit", to: "posts#edit", as: :edit_post)
+patch("/posts/:id", to: "posts#update")
+delete("/posts/:id", to: "posts#destroy", as: :destroy_post)
+
+###########################
+# COMMENTS-related routes #
+###########################
+delete("/comments/:id", to: "comments#destroy", as: :destroy_comment)
+post("/comments/:id", to: "comments#create", as: :post_comments)
+
+########################
+# USERS-related routes #
+########################
+get("/users/new", to: "users#new", as: :new_user)
+post("/users", to: "users#create", as: :users)
+get("/users/:id/edit", to: "users#edit", as: :user)
+patch("/users/:id/edit", to: "users#update")
+get("/users/:id/edit/password", to: "users#edit_password", as: :edit_password)
+post("/users/:id/edit/password", to: "users#update_password")
+
+##########################
+# SESSION-related routes #
+##########################
+get("/session/new", to: "sessions#new", as: :new_session)
+post("/session/new", to: "sessions#create")
+delete("/session", to: "sessions#destroy")
+
+end
diff --git a/blog_on_rails/config/spring.rb b/blog_on_rails/config/spring.rb
new file mode 100644
index 0000000..9fa7863
--- /dev/null
+++ b/blog_on_rails/config/spring.rb
@@ -0,0 +1,6 @@
+%w[
+ .ruby-version
+ .rbenv-vars
+ tmp/restart.txt
+ tmp/caching-dev.txt
+].each { |path| Spring.watch(path) }
diff --git a/blog_on_rails/config/storage.yml b/blog_on_rails/config/storage.yml
new file mode 100644
index 0000000..d32f76e
--- /dev/null
+++ b/blog_on_rails/config/storage.yml
@@ -0,0 +1,34 @@
+test:
+ service: Disk
+ root: <%= Rails.root.join("tmp/storage") %>
+
+local:
+ service: Disk
+ root: <%= Rails.root.join("storage") %>
+
+# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
+# amazon:
+# service: S3
+# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
+# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
+# region: us-east-1
+# bucket: your_own_bucket
+
+# Remember not to checkin your GCS keyfile to a repository
+# google:
+# service: GCS
+# project: your_project
+# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
+# bucket: your_own_bucket
+
+# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
+# microsoft:
+# service: AzureStorage
+# storage_account_name: your_account_name
+# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
+# container: your_container_name
+
+# mirror:
+# service: Mirror
+# primary: local
+# mirrors: [ amazon, google, microsoft ]
diff --git a/blog_on_rails/db/migrate/20181218220644_create_posts.rb b/blog_on_rails/db/migrate/20181218220644_create_posts.rb
new file mode 100644
index 0000000..8fc5dd5
--- /dev/null
+++ b/blog_on_rails/db/migrate/20181218220644_create_posts.rb
@@ -0,0 +1,10 @@
+class CreatePosts < ActiveRecord::Migration[5.2]
+ def change
+ create_table :posts do |t|
+ t.string :title
+ t.text :body
+
+ t.timestamps
+ end
+ end
+end
diff --git a/blog_on_rails/db/migrate/20181219174217_create_comments.rb b/blog_on_rails/db/migrate/20181219174217_create_comments.rb
new file mode 100644
index 0000000..235ab33
--- /dev/null
+++ b/blog_on_rails/db/migrate/20181219174217_create_comments.rb
@@ -0,0 +1,10 @@
+class CreateComments < ActiveRecord::Migration[5.2]
+ def change
+ create_table :comments do |t|
+ t.text :body
+ t.references :post, foreign_key: true
+
+ t.timestamps
+ end
+ end
+end
diff --git a/blog_on_rails/db/migrate/20181219223011_create_users.rb b/blog_on_rails/db/migrate/20181219223011_create_users.rb
new file mode 100644
index 0000000..1988fd8
--- /dev/null
+++ b/blog_on_rails/db/migrate/20181219223011_create_users.rb
@@ -0,0 +1,11 @@
+class CreateUsers < ActiveRecord::Migration[5.2]
+ def change
+ create_table :users do |t|
+ t.string :name
+ t.string :email, index: {unique: true}
+ t.string :password_digest
+
+ t.timestamps
+ end
+ end
+end
diff --git a/blog_on_rails/db/migrate/20181219225120_add_user_references_to_post.rb b/blog_on_rails/db/migrate/20181219225120_add_user_references_to_post.rb
new file mode 100644
index 0000000..cdc9121
--- /dev/null
+++ b/blog_on_rails/db/migrate/20181219225120_add_user_references_to_post.rb
@@ -0,0 +1,5 @@
+class AddUserReferencesToPost < ActiveRecord::Migration[5.2]
+ def change
+ add_reference :posts, :user, foreign_key: true
+ end
+end
diff --git a/blog_on_rails/db/migrate/20181219225132_add_user_references_to_comment.rb b/blog_on_rails/db/migrate/20181219225132_add_user_references_to_comment.rb
new file mode 100644
index 0000000..e067e21
--- /dev/null
+++ b/blog_on_rails/db/migrate/20181219225132_add_user_references_to_comment.rb
@@ -0,0 +1,5 @@
+class AddUserReferencesToComment < ActiveRecord::Migration[5.2]
+ def change
+ add_reference :comments, :user, foreign_key: true
+ end
+end
diff --git a/blog_on_rails/db/migrate/20181220191710_add_admin_to_users.rb b/blog_on_rails/db/migrate/20181220191710_add_admin_to_users.rb
new file mode 100644
index 0000000..aa6a7e9
--- /dev/null
+++ b/blog_on_rails/db/migrate/20181220191710_add_admin_to_users.rb
@@ -0,0 +1,5 @@
+class AddAdminToUsers < ActiveRecord::Migration[5.2]
+ def change
+ add_column :users, :admin, :boolean, default: false
+ end
+end
diff --git a/blog_on_rails/db/schema.rb b/blog_on_rails/db/schema.rb
new file mode 100644
index 0000000..fed86c1
--- /dev/null
+++ b/blog_on_rails/db/schema.rb
@@ -0,0 +1,50 @@
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended that you check this file into your version control system.
+
+ActiveRecord::Schema.define(version: 2018_12_20_191710) do
+
+ # These are extensions that must be enabled in order to support this database
+ enable_extension "plpgsql"
+
+ create_table "comments", force: :cascade do |t|
+ t.text "body"
+ t.bigint "post_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.bigint "user_id"
+ t.index ["post_id"], name: "index_comments_on_post_id"
+ t.index ["user_id"], name: "index_comments_on_user_id"
+ end
+
+ create_table "posts", force: :cascade do |t|
+ t.string "title"
+ t.text "body"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.bigint "user_id"
+ t.index ["user_id"], name: "index_posts_on_user_id"
+ end
+
+ create_table "users", force: :cascade do |t|
+ t.string "name"
+ t.string "email"
+ t.string "password_digest"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.boolean "admin", default: false
+ t.index ["email"], name: "index_users_on_email", unique: true
+ end
+
+ add_foreign_key "comments", "posts"
+ add_foreign_key "comments", "users"
+ add_foreign_key "posts", "users"
+end
diff --git a/blog_on_rails/db/seeds.rb b/blog_on_rails/db/seeds.rb
new file mode 100644
index 0000000..9fd0d97
--- /dev/null
+++ b/blog_on_rails/db/seeds.rb
@@ -0,0 +1,60 @@
+# This file should contain all the record creation needed to seed the database with its default values.
+# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
+#
+# Examples:
+#
+# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
+# Character.create(name: 'Luke', movie: movies.first)
+
+Post.destroy_all
+Comment.destroy_all
+User.destroy_all
+
+PASSWORD = "supersecret"
+
+super_user = User.create(
+ name: "Codecore",
+ email: "codecore@gmail.com",
+ password: PASSWORD,
+ admin: true
+)
+
+10.times do
+ name = Faker::Name.name
+ email = "#{name.downcase}@example.com"
+ User.create(
+ name: name,
+ email: email,
+ password: PASSWORD
+ )
+end
+users = User.all
+
+50.times do
+ title = Faker::Lorem.sentence
+ body = Faker::Lorem.paragraph_by_chars
+ created_at = Faker::Date.backward(365 * 5)
+
+ p = Post.create(
+ title: title,
+ body: body,
+ created_at: created_at,
+ updated_at: created_at,
+ user: users.sample
+ )
+
+ if p.valid?
+ rand(0..10).times do
+ p.comments << Comment.new(
+ body: Faker::Hacker.say_something_smart,
+ user: users.sample
+ )
+ end
+ end
+end
+
+posts = Post.all
+comments = Comment.all
+puts "I've seeded #{posts.count} posts"
+puts "I've seeded #{comments.count} comments"
+puts "I've seeded #{users.count} users"
\ No newline at end of file
diff --git a/blog_on_rails/lib/assets/.keep b/blog_on_rails/lib/assets/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/blog_on_rails/lib/tasks/.keep b/blog_on_rails/lib/tasks/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/blog_on_rails/log/.keep b/blog_on_rails/log/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/blog_on_rails/package.json b/blog_on_rails/package.json
new file mode 100644
index 0000000..c8d82a5
--- /dev/null
+++ b/blog_on_rails/package.json
@@ -0,0 +1,5 @@
+{
+ "name": "blog_on_rails",
+ "private": true,
+ "dependencies": {}
+}
diff --git a/blog_on_rails/public/404.html b/blog_on_rails/public/404.html
new file mode 100644
index 0000000..2be3af2
--- /dev/null
+++ b/blog_on_rails/public/404.html
@@ -0,0 +1,67 @@
+
+
+
+ The page you were looking for doesn't exist (404)
+
+
+
+
+
+
+
+
+
The page you were looking for doesn't exist.
+
You may have mistyped the address or the page may have moved.
+
+
If you are the application owner check the logs for more information.
+
+
+
diff --git a/blog_on_rails/public/422.html b/blog_on_rails/public/422.html
new file mode 100644
index 0000000..c08eac0
--- /dev/null
+++ b/blog_on_rails/public/422.html
@@ -0,0 +1,67 @@
+
+
+
+ The change you wanted was rejected (422)
+
+
+
+
+
+
+
+
+
The change you wanted was rejected.
+
Maybe you tried to change something you didn't have access to.
+
+
If you are the application owner check the logs for more information.
+
+
+
diff --git a/blog_on_rails/public/500.html b/blog_on_rails/public/500.html
new file mode 100644
index 0000000..78a030a
--- /dev/null
+++ b/blog_on_rails/public/500.html
@@ -0,0 +1,66 @@
+
+
+
+ We're sorry, but something went wrong (500)
+
+
+
+
+
+
+
+
+
We're sorry, but something went wrong.
+
+
If you are the application owner check the logs for more information.
+
+
+
diff --git a/blog_on_rails/public/apple-touch-icon-precomposed.png b/blog_on_rails/public/apple-touch-icon-precomposed.png
new file mode 100644
index 0000000..e69de29
diff --git a/blog_on_rails/public/apple-touch-icon.png b/blog_on_rails/public/apple-touch-icon.png
new file mode 100644
index 0000000..e69de29
diff --git a/blog_on_rails/public/favicon.ico b/blog_on_rails/public/favicon.ico
new file mode 100644
index 0000000..e69de29
diff --git a/blog_on_rails/public/robots.txt b/blog_on_rails/public/robots.txt
new file mode 100644
index 0000000..37b576a
--- /dev/null
+++ b/blog_on_rails/public/robots.txt
@@ -0,0 +1 @@
+# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
diff --git a/blog_on_rails/storage/.keep b/blog_on_rails/storage/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/blog_on_rails/tmp/.keep b/blog_on_rails/tmp/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/blog_on_rails/vendor/.keep b/blog_on_rails/vendor/.keep
new file mode 100644
index 0000000..e69de29