Ruby on Rails
The Single Engineer Framework
Radoslav Stankov
Slide 2
Slide 2 text
!
Slide 3
Slide 3 text
Radoslav Stankov
@rstankov rstankov.com
Slide 4
Slide 4 text
https://tips.rstankov.com
Slide 5
Slide 5 text
No content
Slide 6
Slide 6 text
I began my web development career using
Flash, PHP, and JavaScript at an agency in
Dobrich in 2002.
Slide 7
Slide 7 text
I was 15 "
Slide 8
Slide 8 text
... after 22 years #
Slide 9
Slide 9 text
here some of the technologies, I
have worked with...
Slide 10
Slide 10 text
No content
Slide 11
Slide 11 text
Careers in tech are long, and technology trends come and go.
You won't be able to have a meaningful career working with a single
technology your whole career.
Slide 12
Slide 12 text
No content
Slide 13
Slide 13 text
- one developer (me) $
- management portal %
- implement a mobile app &
- for iOS ' / Android (
Slide 14
Slide 14 text
Building mapping )
Mobile app &
Issue tracker *
Employees +
Bulletin board ,
Notifications -
Taxation .
Contacts /
Omni search 0
Reporting 1
Printing 2
Bookkeeping 3
Voting 4
Financials 5
Homebook 6
Debtors 7
Bulk operations ⚙
Messaging 9
Calendar :
Funds ;
ePay / EasyPay <
Bank imports =
Invoicing >
Warranty Issues ?
Technicians @
Individual accounts A
Business accounts )
Audit logs B
Archiving C
Trials D
Demo E
I18n F G H
Marketing site I
Slide 15
Slide 15 text
& Mobile stack J
Slide 16
Slide 16 text
% Web stack J
Slide 17
Slide 17 text
Ruby on Rails and its ecosystem enabled me to develop Angry Building
single-handedly. It felt like having a cheat code.
Slide 18
Slide 18 text
No content
Slide 19
Slide 19 text
Ruby on Rails
Slide 20
Slide 20 text
Ruby on Rails
Slide 21
Slide 21 text
Ruby on Rails
Slide 22
Slide 22 text
Ruby on Rails
Slide 23
Slide 23 text
Ruby
Ruby is an interactive, object-
oriented programming language.
Its motto is:
"Optimized for programmer
happiness"
Slide 24
Slide 24 text
https://rubygems.org/
Slide 25
Slide 25 text
Ruby on Rails
Ruby on Rails is a web application framework.
Slide 26
Slide 26 text
No content
Slide 27
Slide 27 text
Who uses Ruby? K
Slide 28
Slide 28 text
No content
Slide 29
Slide 29 text
No content
Slide 30
Slide 30 text
... Ruby on Rails old and boring,
designed for monoliths L
class Person
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
end
def first_name
@first_name
end
def first_name=(value)
@first_name = value
end
Classes
Slide 69
Slide 69 text
end
def first_name=(value)
@first_name = value
end
def last_name
@last_name
end
def last_name=(value)
@last_name = value
end
def full_name
"#{first_name} + #{last_name}"
end
end
Classes
Slide 70
Slide 70 text
Classes
class Person
attr_reader :first_name, :last_name
attr_writer :first_name, :last_name
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
end
def full_name
"#{first_name} + #{last_name}"
end
end
Slide 71
Slide 71 text
Classes
class Person
attr_accessor :first_name, :last_name
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
end
def full_name
"#{first_name} + #{last_name}"
end
end
Slide 72
Slide 72 text
Meta programming
class Person
attr_accessor :first_name, :last_name
end
Slide 73
Slide 73 text
No content
Slide 74
Slide 74 text
Meta Programming
Slide 75
Slide 75 text
R Nothing is special
S Everything is an object
T No definitions, just executions
U Cool syntax V
Meta programming
Slide 76
Slide 76 text
Open classes
class Array
def first
self[0]
end
def second
self[1]
end
end
array = [1, 2, 3, 4]
array.first # 1
array.second # 2
Slide 77
Slide 77 text
class MyClass
puts "I'll be executed"
unless RUBY_VERSION >= "3.3.3"
puts "I'll be executed after ruby 3.3.3"
def some_method
# ... code
end
end
end
No definitions, just executions
Slide 78
Slide 78 text
Meta programming
class Person
attr_accessor :first_name, :last_name
end
Slide 79
Slide 79 text
Meta programming
class Person
def first_name
@first_name
end
def first_name=(value)
@first_name = value
end
end
Slide 80
Slide 80 text
Meta programming
class Person
define_method(:first_name) do
@first_name
end
define_method(:first_name=) do |value|
@first_name = value
end
end
Slide 81
Slide 81 text
Meta programming
class Person
define_method(:first_name) do
instance_variable_get(:@first_name)
end
define_method(:first_name=) do |value|
instance_variable_set(:@first_name, value)
end
end
Slide 82
Slide 82 text
Meta programming
class Person
define_method(:first_name) do
instance_variable_get :@first_name
end
define_method(:first_name=) do |value|
instance_variable_set :@first_name, value
end
end
Slide 83
Slide 83 text
Meta programming
class Person
attr_accessor :first_name, :last_name
end
Slide 84
Slide 84 text
Meta programming
class Person
def self.attr_accessor(attribute)
define_method(attribute) do
instance_variable_get :"@#{attribute}"
end
define_method(:"#{attribute}=") do |value|
instance_variable_set :"@#{attribute}", value
end
end
end
Slide 85
Slide 85 text
Meta programming
class Person
def self.attr_accessor(*attributes)
attributes.each do |attribute|
define_method(attribute) do
instance_variable_get :"@#{attribute}"
end
define_method(:"#{attribute}=") do |value|
instance_variable_set :"@#{attribute}", value
end
end
end
end
Slide 86
Slide 86 text
Meta programming
class Person
attr_accessor :first_name, :last_name
end
Slide 87
Slide 87 text
No content
Slide 88
Slide 88 text
No content
Slide 89
Slide 89 text
No content
Slide 90
Slide 90 text
No content
Slide 91
Slide 91 text
No content
Slide 92
Slide 92 text
W Model View Controller (MVC)
X Batteries included
Y Convention over configuration
Z Extendible platform
Slide 93
Slide 93 text
W Model View Controller (MVC)
Slide 94
Slide 94 text
W Model View Controller (MVC)
Slide 95
Slide 95 text
W Model View Controller (MVC)
Slide 96
Slide 96 text
W Model View Controller (MVC)
Slide 97
Slide 97 text
W Model View Controller (MVC)
Slide 98
Slide 98 text
W Model View Controller (MVC)
Slide 99
Slide 99 text
W Model View Controller (MVC)
Slide 100
Slide 100 text
W Model View Controller (MVC)
Slide 101
Slide 101 text
W Model View Controller (MVC)
Slide 102
Slide 102 text
W Model View Controller (MVC)
Slide 103
Slide 103 text
No content
Slide 104
Slide 104 text
ActiveSupport - utilities
ActiveModel - base model & validations
ActiveRecord - object relation mapper (ORM)
ActiveJob - background job processing
ActiveStorage - file uploads
ActionController - Controller from MVC
ActionView - View from MVC
ActionMailer - Sending emails
ActionMailbox - Receiving & processing emails
ActionCable - Web Socket & real time
ActionText - Rich text editing
Propshaft - assets delivery
I18n - internalization
X Batteries included
Slide 105
Slide 105 text
Y Convention over configuration
Slide 106
Slide 106 text
https://github.com/maybe-finance/maybe
https://github.com/discourse/discourse
https://github.com/forem/forem
https://github.com/mastodon/mastodon
https://github.com/thoughtbot/upcase
https://github.com/feedbin/feedbin
https://gitlab.com/gitlab-org/gitlab
Open Source Apps
Slide 107
Slide 107 text
https://blog.rstankov.com/top-8-ruby-on-rails-engines/
Z Extendible platform
Slide 108
Slide 108 text
Sidekiq
Slide 109
Slide 109 text
Blazer
Slide 110
Slide 110 text
Lookbook
Slide 111
Slide 111 text
Flipper
Slide 112
Slide 112 text
GraphiQL
Slide 113
Slide 113 text
... and a lot more ✨
Slide 114
Slide 114 text
https://rubygems.org/
Slide 115
Slide 115 text
No content
Slide 116
Slide 116 text
rails new blog
rails generate scaffold post title:string content:text
Slide 117
Slide 117 text
No content
Slide 118
Slide 118 text
db/migrate/[...]_create_posts.rb
class CreatePosts < ActiveRecord::Migration[7.1]
def change
create_table :posts do |t|
t.string :title, null: false
t.text :content, null: false
t.timestamps
end
end
end
Slide 119
Slide 119 text
rails db:migrate
Slide 120
Slide 120 text
No content
Slide 121
Slide 121 text
class Post < ApplicationRecord
validates :title, presence: true
validates :content, presence: true
end
app/models/post.rb
Slide 122
Slide 122 text
Rails.application.routes.draw do
resources :posts
# Define your application routes per the DSL in
# https://guides.rubyonrails.org/routing.html
# Reveal health status on /up that returns 200
# if the app boots with no exceptions, otherwise 500.
# Can be used by load balancers and uptime monitors to
# verify that the app is live.
get "up" => "rails/health#show", as: :rails_health_check
# Defines the root path route ("/")
# root "posts#index"
end
config/routes.rb
Slide 123
Slide 123 text
class PostsController < ApplicationController
# GET /posts
def index
@posts = Post.all
end
# GET /posts/1
def show
@post = Post.find(params[:id])
end
# GET /posts/new
def new
@post = Post.new
end
# GET /posts/1/edit
def edit
@post = Post.find(params[:id])
end
# POST /posts
def create app/controllers/posts_controller.rb
Slide 124
Slide 124 text
# POST /posts
def create
@post = Post.new(post_params)
if @post.save
redirect_to post_url(@post), notice: "Post was successfully cr
else
render :new, status: :unprocessable_entity
end
end
# PATCH/PUT /posts/1
def update
@post = Post.find(params[:id])
if @post.update(post_params)
redirect_to post_url(@post), notice: "Post was successfully up
else
render :edit, status: :unprocessable_entity
end
end
# DELETE /posts/1
app/controllers/posts_controller.rb
Slide 125
Slide 125 text
if @post.update(post_params)
redirect_to post_url(@post), notice: "Post was successfully up
else
render :edit, status: :unprocessable_entity
end
end
# DELETE /posts/1
def destroy
@post = Post.find(params[:id])
@post.destroy!
redirect_to posts_url, notice: "Post was successfully destroyed.
end
private
def post_params
params.require(:post).permit(:title, :content)
end
end
app/controllers/posts_controller.rb
Slide 126
Slide 126 text
<%= notice %>
Posts
<% @posts.each do |post| %>
<%= render post %>
<%= link_to "Show this post", post %>
<% end %>
<%= link_to "New post", new_post_path %>
app/views/posts/index.html.erb
Slide 127
Slide 127 text
<%= form_with(model: post) do |form| %>
<% if post.errors.any? %>
<%= pluralize(post.errors.count, "error") %> prohibited this post from bei