Slide 1

Slide 1 text

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

Slide 31

Slide 31 text

https://newsletter.pragmaticengineer.com/p/what-is-old-is-new-again

Slide 32

Slide 32 text

https://newsletter.pragmaticengineer.com/p/what-is-old-is-new-again

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

... one interesting story

Slide 35

Slide 35 text

... one interesting story ... maybe $

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

https://github.com/maybe-finance/maybe

Slide 39

Slide 39 text

Ruby

Slide 40

Slide 40 text

M Syntax N Symbols N Blocks O Expressions P Everything is object Q Open classes

Slide 41

Slide 41 text

Variables a = 1 # Number b = "string" # String c = [1, 2, 3, 4] # Array d = { key: 'value' } # Hash

Slide 42

Slide 42 text

Symbols a = :key hash[:key]

Slide 43

Slide 43 text

Everything is an object person.name "string".size array.empty? array[0] == array.first array[1] == array.second array[array.size - 1] == array.last 1.day.ago 1.day.ago - 2.hours

Slide 44

Slide 44 text

puts("string") puts "string" Method calling

Slide 45

Slide 45 text

Blocks 5.times { puts "Ruby is cool!" } 5.times do puts "Ruby is cool!" end

Slide 46

Slide 46 text

Blocks [1,2,3,4].each { |value| puts value } # => [1, 2, 3, 4] [1,2,3,4].map { |value| value * value } # => [1, 4, 9, 16] [1,2,3,4].reduce { |a, b| a + b } # => 10

Slide 47

Slide 47 text

Blocks [1,2,3,4].each { puts _1 } # => [1, 2, 3, 4] [1,2,3,4].map { _1 * _1 } # => [1, 4, 9, 16] [1,2,3,4].reduce { _1 + _1 } # => 10

Slide 48

Slide 48 text

Blocks File.open('file.txt') do |file| file.write 'content' end

Slide 49

Slide 49 text

Blocks File.open('file.txt') do |file| file << 'content' end

Slide 50

Slide 50 text

Blocks File.open('file.txt') do _1 << 'content' end

Slide 51

Slide 51 text

Blocks File.open('file.txt') { _1 << 'content' }

Slide 52

Slide 52 text

Blocks def method_with_block(value) yield value end value = method_with_block(5) { |v| v + 4 } puts value # 9

Slide 53

Slide 53 text

Blocks def method_with_block(value, &block) block.call(value) end value = method_with_block(5) { |v| v + 4 } puts value # 9

Slide 54

Slide 54 text

Expressions def explain_number(value) if value % 2 result = 'even' else result = 'odd' end return result end

Slide 55

Slide 55 text

Expressions def explain_number(value) if value % 2 result = 'even' else result = 'odd' end result end

Slide 56

Slide 56 text

Expressions def explain_number(value) if value.even? result = 'even' else result = 'odd' end result end

Slide 57

Slide 57 text

Expressions def explain_number(value) result = if value.even? 'even' else 'odd' end result end

Slide 58

Slide 58 text

Expressions def explain_number(value) if value.even? 'even' else 'odd' end end

Slide 59

Slide 59 text

Expressions def error_message(value) if !value.present? return nil end return 'value is empty' end

Slide 60

Slide 60 text

Expressions def error_message(value) if !value.present? return nil end 'value is empty' end

Slide 61

Slide 61 text

Expressions def error_message(value) unless value.present? return nil end 'value is empty' end

Slide 62

Slide 62 text

Expressions def error_message(value) return nil unless value.present? 'value is empty' end

Slide 63

Slide 63 text

Expressions def error_message(value) return unless value.present? 'value is empty' end

Slide 64

Slide 64 text

Expressions def error_message(value) 'value is empty' if value.blank? end

Slide 65

Slide 65 text

Expressions def error_message(value) return 'value is empty' if value.blank? return "value #{value} is to long" if value.size > 100 end

Slide 66

Slide 66 text

Expressions def error_message(value) if value.blank? 'value is empty' elsif value.size > 100 "value #{value} is to long" end end

Slide 67

Slide 67 text

Classes me = Person.new("Radoslav", "Stankov")
 me.first_name # Radoslav me.last_name # Stankov me.full_name # Radoslav Stankov

Slide 68

Slide 68 text

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
    <% post.errors.each do |error| %>
  • <%= error.full_message %>
  • <% end %>

<% end %>
<%= form.label :title, style: "display: block" %> <%= form.text_field :title %>
<%= form.label :content, style: "display: block" %> <%= form.text_area :content %>
<%= form.submit %>
<% end %> app/views/posts/_form.html.erb

Slide 128

Slide 128 text

rails server

Slide 129

Slide 129 text

No content

Slide 130

Slide 130 text

No content

Slide 131

Slide 131 text

No content

Slide 132

Slide 132 text

No content

Slide 133

Slide 133 text

No content

Slide 134

Slide 134 text

No content

Slide 135

Slide 135 text

No content

Slide 136

Slide 136 text

No content

Slide 137

Slide 137 text

No content

Slide 138

Slide 138 text

rails action_text:install

Slide 139

Slide 139 text

No content

Slide 140

Slide 140 text

bundle

Slide 141

Slide 141 text

No content

Slide 142

Slide 142 text

rails server

Slide 143

Slide 143 text

No content

Slide 144

Slide 144 text

class Post < ApplicationRecord validates :title, presence: true validates :content, presence: true has_rich_text :content end app/models/post.rb

Slide 145

Slide 145 text

<%= form_with(model: post) do |form| %> <% if post.errors.any? %>

<%= pluralize(post.errors.count, "error") %> prohibited this post from bei
    <% post.errors.each do |error| %>
  • <%= error.full_message %>
  • <% end %>

<% end %>
<%= form.label :title, style: "display: block" %> <%= form.text_field :title %>
<%= form.label :content, style: "display: block" %> <%= form.rich_text_area :content %>
<%= form.submit %>
<% end %> app/views/posts/_form.html.erb

Slide 146

Slide 146 text

No content

Slide 147

Slide 147 text

No content

Slide 148

Slide 148 text

https://rubyonrails.org/

Slide 149

Slide 149 text

Learning resources

Slide 150

Slide 150 text

https://tips.rstankov.com

Slide 151

Slide 151 text

https://www.youtube.com/watch?v=X2sgQ38UDVY

Slide 152

Slide 152 text

https://bit.ly/4cznIfA

Slide 153

Slide 153 text

No content

Slide 154

Slide 154 text

https://rubybanitsa.com/

Slide 155

Slide 155 text

No content

Slide 156

Slide 156 text

https://balkanruby.com/

Slide 157

Slide 157 text

https://rstankov.com/appearances