Speech of Nihad Abbasov, Backend Engineer at Digital Classifieds, at Ruby Meditation #26 Kyiv 16.02.2019
Next conference - http://www.rubymeditation.com/
What to expect from Rails 6? Review of new features.
Announcements and conference materials https://www.fb.me/RubyMeditation
News https://twitter.com/RubyMeditation
Photos https://www.instagram.com/RubyMeditation
The stream of Ruby conferences (not just ours) https://t.me/RubyMeditation
18. app/mailboxes/posts_mailbox.rb
class PostsMailbox < ApplicationMailbox
before_processing :ensure_sender_is_a_user
private
def ensure_sender_is_a_user
unless User.exist?(email: mail.from)
bounce_with UserMailer.missing(inbound_email)
end
end
end
36. Request is sent to the replica
● The request is a read request (GET or HEAD)
● AND It's been 5 seconds since the last write
to the database
37. Request is sent to the primary
● It's not a GET/HEAD request (ie is a POST,
PATCH, etc)
● Has been less than 5 seconds since the last
write to the database
39. Database connection switching API
Connects a model to the databases specified:
# in your model:
connects_to database: {
writing: :primary,
reading: :primary_replica
}
database
keyword
takes a hash
consisting of
a role and a
database_key
47. Enumerable#index_with
post = Post.new(
title: "hey there",
body: "what's up?"
)
%i[title body].index_with do |a|
post.public_send(a)
end
# => { title: "hey there", body:
"what's up?" }
Converts an enumerable to a hash:
keys are
enumerable
items with
the values
returned in
the block
49. Command for changing databases
$ rails db:system:change --to=postgresql
$ rails db:system:change --to=sqlite3
Modifies config/database.yml and Gemfile
50. `before?` & `after?` methods in date & time classes
date1.after? date2
date1.before? date2
# same as:
date1 > date2
date1 < date2
For comparing dates and times:
Makes date
and time
comparisons
more human
readable
51. Endless ranges in where
relation.where(
column: 1..Float::INFINITY
)
# is equivalent to:
relation.where(column: (1..))
Support for
endless
ranges
introduced in
Ruby 2.6
52. New uploaded files stored on save
@user.avatar = params[:avatar]
@user.save
The uploaded
file is stored
when @user
is
successfully
saved