Ruby on Rails
The Single Engineer Framework
Radoslav Stankov
Slide 2
Slide 2 text
Radoslav Stankov
@rstankov rstankov.com
Slide 3
Slide 3 text
https://tips.rstankov.com
Slide 4
Slide 4 text
No content
Slide 5
Slide 5 text
No content
Slide 6
Slide 6 text
SIMPLIFYING
PROPERTY
MANAGEMENT FOR
MODERN COMMUNITIES
LIVO.ME
Slide 7
Slide 7 text
No content
Slide 8
Slide 8 text
I began my web development career using
Flash, PHP, and JavaScript at an agency in
Dobrich in 2002.
Slide 9
Slide 9 text
I was 15 "
Slide 10
Slide 10 text
... after 23 years #
Slide 11
Slide 11 text
here some of the technologies, I
have worked with...
Slide 12
Slide 12 text
No content
Slide 13
Slide 13 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 14
Slide 14 text
No content
Slide 15
Slide 15 text
$ Side project
Slide 16
Slide 16 text
- one developer (me) %
- management portal &
- implement a mobile app '
- for iOS ( / Android )
Slide 17
Slide 17 text
Building mapping *
Mobile app '
Issue tracker +
Employees ,
Bulletin board -
Notifications .
Taxation /
Contacts 0
Omni search 1
Reporting 2
Printing 3
Bookkeeping 4
Voting 5
Financials 6
Homebook 7
Debtors 8
Bulk operations ⚙
Messaging :
Calendar ;
Funds <
ePay / EasyPay =
Bank imports >
Invoicing ?
Warranty Issues @
Technicians A
Individual accounts B
Business accounts *
Audit logs C
Archiving D
Trials E
Demo F
I18n G H I
Marketing site J
Slide 18
Slide 18 text
' Mobile stack K
Slide 19
Slide 19 text
& Web stack K
Slide 20
Slide 20 text
Ruby on Rails and its ecosystem enabled me to develop Angry Building
single-handedly. It felt like having a cheat code.
Slide 21
Slide 21 text
No content
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
No content
Slide 26
Slide 26 text
Ruby on Rails
Ruby on Rails is a web application framework.
Slide 27
Slide 27 text
No content
Slide 28
Slide 28 text
Who uses Ruby? L
Slide 29
Slide 29 text
No content
Slide 30
Slide 30 text
No content
Slide 31
Slide 31 text
... Ruby on Rails old and boring,
designed for monoliths M
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 84
Slide 84 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 85
Slide 85 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 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
Meta Programming
Slide 89
Slide 89 text
X Nothing is special
Y Everything is an object
Z No definitions, just executions
[ Cool syntax \
Meta programming
Slide 90
Slide 90 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 91
Slide 91 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 92
Slide 92 text
Meta programming
class Person
attr_accessor :first_name, :last_name
end
Slide 93
Slide 93 text
Meta programming
class Person
def first_name
@first_name
end
def first_name=(value)
@first_name = value
end
end
Slide 94
Slide 94 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 95
Slide 95 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 96
Slide 96 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 97
Slide 97 text
Meta programming
class Person
attr_accessor :first_name, :last_name
end
Slide 98
Slide 98 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 99
Slide 99 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 100
Slide 100 text
Meta programming
class Person
attr_accessor :first_name, :last_name
end
Slide 101
Slide 101 text
No content
Slide 102
Slide 102 text
No content
Slide 103
Slide 103 text
No content
Slide 104
Slide 104 text
No content
Slide 105
Slide 105 text
N Model View Controller (MVC)
Slide 106
Slide 106 text
N Model View Controller (MVC)
Slide 107
Slide 107 text
N Model View Controller (MVC)
Slide 108
Slide 108 text
N Model View Controller (MVC)
Slide 109
Slide 109 text
N Model View Controller (MVC)
Slide 110
Slide 110 text
N Model View Controller (MVC)
Slide 111
Slide 111 text
N Model View Controller (MVC)
Slide 112
Slide 112 text
N Model View Controller (MVC)
Slide 113
Slide 113 text
N Model View Controller (MVC)
Slide 114
Slide 114 text
N Model View Controller (MVC)
Slide 115
Slide 115 text
rails new blog
rails generate scaffold post title:string content:text
Slide 116
Slide 116 text
No content
Slide 117
Slide 117 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 118
Slide 118 text
rails db:migrate
Slide 119
Slide 119 text
No content
Slide 120
Slide 120 text
class Post < ApplicationRecord
validates :title, presence: true
validates :content, presence: true
end
app/models/post.rb
Slide 121
Slide 121 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 122
Slide 122 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
app/controllers/posts_controller.rb
Slide 123
Slide 123 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 124
Slide 124 text
<%= form_with(model: post) do |form| %>
<% if post.errors.any? %>
<%= pluralize(post.errors.count, "error") %> prohibited this post from bei