Rubyland

news, opinion, tutorials, about ruby, aggregated
Sources About
Awesome Ruby Newsletter 

💎 Issue 192 - Yukihiro Matsumoto: "Ruby is designed for humans, not machines"

Valentino Gagliardi 

Understanding the Firefox Dev Tools Architecture, and How to Start Contributing to Firefox

This year I decided to contribute more to open source projects and since I’ve made the resolution to switch to Firefox from Chrome I’ve also got the chance to find an interesting bug to work on.

In this post I want to share my learnings in the hope that more people could start contributing to Firefox.

Enjoy!

Contributing to Firefox: a bit of backstory

In Firefox Dev Tools I wanted a “Store as global variable” option in the Scopes panel. The Scopes panel appears in the debugger tab when you stop the script with a breakpoint, much like Chrome Dev Tools.

As of now the only thing that you can do on an object in the panel is adding a watchpoint, that is, a watcher which fires…

Ruby Weekly 

Matz: 'Ruby is designed for humans, not machines'

#485 — January 23, 2020

Read on the Web

Ruby Weekly

Yukihiro Matsumoto (Matz) Interview from RubyRussia — An enjoyable chat where the “nice” of Matz really shines through. He covers topics like language design successes and failures and how type checking is coming to Ruby. There's a 20 minute video version available too.

Evrone

Modern Ruby Serializers — A look at the history of various serializers, leading to the introduction of SimpleAMS, a new serialization library by the author and how it compares to other options.

Filippos Vasilakis

The Easiest Way to Run Redis — Better monitoring,…

code.dblock.org | tech blog 

Restoring Data into a MongoDB Dokku Container

I’ve been running a pet project using Dokku on DigitalOcean for a number of years with MongoDB, backing up data into Dropbox. See Running Slack Bots on DigitalOcean with Dokku and Backing up MongoDB Databases in Dokku Containers to Dropbox.

Today I had to selectively export data from a backup, and restore this data into a MongoDB running inside a Dokku container. This was a bit tedious.

Exporting a Subset of Data

I am dealing with slack-gamebot data, which contains a teams collection with a row per team and related data in other collections, including users and matches. I wrote a bash script to export this data.

Construct a query string, eg. {"team_id":"ID"} and fetch the _id value for…

Ruby on Rails Podcast 

304: Legacy Code Wisdom with Alexey Chernov

Alexey Chernov is a Ruby on Rails consultant at JetThoughts. Over the years, he has built MVPs and consulted to improve legacy code, scale up the remote team and achieve an effective development process. He and Brittany dive deep into approaching legacy RoR projects.

Links for this episode:

Greater Than Code 

166: From Software Engineer to Management with Phil Wheeler

01:10 - Phil’s Superpower: Putting Himself in Others’ Shoes.

02:03/09:14 From Software Engineer to Management

  • Empathy Through The Career Shift
  • The Learning Curve
  • Making a Conscious Choice To Switch
  • Gaining Leadership Skills
  • Making Your Own Opportunities

03:34 - How Phil Came Into The Greater Than Code Community

05:54 - Commonalities Between Issues Between USA and NZ

  • Inclusion, Equality in Technology

07:05 - Life Science Software Experience

  • Cloud Based, LT
  • Awareness of Accessibility

16:45 - To Get Into Management or Not

18:55 - The Parallels Of Management And Parenting

26:17 - Working From…

Saeloun Blog 

Ruby 2.7 allows placing of comment lines between fluent dots

With Ruby 2.7, comment lines can now be placed between fluent dots.

Before Ruby 2.7

Class
  # .methods or comment
  .inspect
=> syntax error, unexpected '.', expecting end-of-input

After Ruby 2.7

Class
  # .methods or comment
  .inspect
=> "Class"

This feature comes in handy especially when debugging some set of changes or when we need to explain the purpose behind a particular chained method separately.

For instance, following is allowed,

Post
  # Complex scope call which needs separate comment to explain
  .only_published_with_info(filter)
  # .with_single_author # Commented for debugging
  .with_generic_notes

Note that placing one or more blank lines between the chained…

Saeloun Blog 

Rails 6.1 adds query method missing to find orphan records

Rails 6.1 adds a query method missing to search for orphan records within ActiveRecord.

We often find ourselves querying an ActiveRecord model for orphan objects for reasons like cleanup or bulk updates.

Example

Let us consider the following models.

# app/models/manager.rb
class Manager < ApplicationRecord
  has_many :job_listings
end
# app/models/job_listing.rb
class JobListing < ApplicationRecord
  has_many :job_applications
  belongs_to :manager
end
# app/models/job_application.rb
class JobApplication < ApplicationRecord
  belongs_to :job_listing
end

Before Rails 6.1

Now let us try to find all the job listings which do not have a manager assigned.

[1] pry(main)> JobListing.lef…
Martian Chronicles, Evil Martians’ team blog 

What I learned as a developer from accidents in space

Author: Andrey Sitnik, Author of PostCSS and Autoprefixer, Lead Front-end Developer at Evil Martians

Join Andrey Sitnik, the author of PostCSS and Autoprefixer, for a round of tales from the Soviet Space Age and learn the lessons he took from them to become a better developer and open-source maintainer. A failed docking attempt, a dramatic reentry, and a first genuine fender-bender in orbit—what does it all have to do with modern web development? Stay tuned to find out!

I’ve been passionate about space exploration for as long as I can remember: people who know me in person heard more space stories than they signed up for.

Before joining Evil Martians, I used to be an administrator…

Fast Ruby Blog 

The Complete Guide to Migrate to Strong Parameters

Migrating from Protected Attributes to Strong Parameters in a Rails project can be a huge step of the upgrade process. Especially when we are upgrading a large application. This guide is meant to help you tackle that step faster and with a lot less pain.

Protected Attributes & Strong Parameters

To give you a bit of context, let's recap what Protected Attributes and Strong Parameters actually are. They are two different Rails implementations for protecting attributes from end-user injection (a.k.a. Mass Assignment)

To understand what the benefits are of Strong Parameters over Protected Attributes, I recommend checking this RailsCasts episode.

Protected Attributes was part of the Rails…

All Ruby Podcasts by Devchat.tv 

MRS 102: Elia Schito

My Ruby Story this week welcomes Elia Schito, a senior developer for Nebulab. Elia has been working with Ruby for the past 12 years. Charles starts off by asking how Elia became a developer.

Host: Charles Max Wood

Joined By Special Guest: Elia Schito

Sponsors

______________________________________

"The MaxCoders Guide to Finding Your Dream Developer Job" by Charles Max Wood is now available on Amazon. Get Your Copy Today!

______________________________________

 

Links

Picks

Charles Max…

All Ruby Podcasts by Devchat.tv 

RR 447: All About Kafka and Oracle with Bob Quillin and Karthik Gaekwad

Bob Quillin and Karthik Gaekwad are on the Oracle developer relations team. Karthik has been on Ruby Rogues previously, and he explains how he went from the Kubernetes team to developer relations. They begin the show by explaining what Kafka is, the leading open-source event streaming platform that Oracle is compatible with. It allows cloud developers to build, publish, and subscribe models for streams of records in addition to many other functions. Systems that used to take a long time to make have become very small and simple with Kafka. Kafka stands out from other message queueing systems because of its robust nature and scalability. 

Bob goes into more depth about the evolution of…

The Bike Shed 

229: Nothing but Positive Fire

On this week's episode, Steph and Chris catch up in their first recording of 2020. They discuss git workflows and the surprisingly strong opinions often associated with them, testing at all levels of your application, Steph gives a quick summary of her Ember adventures, and they round out the discussion with some new years systems building and Star Wars reviews.

This episode is brought to you by Clubhouse. Click through to get 2 free months on any paid plan.

GoRails Screencasts 

How to use AWS Cloud9 for Ruby on Rails development

Ever wanted an editor and Rails environment you can use anywhere? Cloud9 is the perfect option for this and can run on an EC2 instance in your AWS account.
Pat Shaughnessy 

Downloading 100,000 Files Using Async Rust


Rust's new async/await feature makes it
easy to stop and start asynchronous tasks

(from: Wikimedia Commons)

Imagine if you had a text file containing thousands of URLs:

$ cat urls.txt
https://example.com/1.html
https://example.com/2.html
https://example.com/3.html

etc...

https://example.com/99999.html
https://example.com/100000.html

…and you needed to download all of those HTML pages efficiently. How would you do it? Maybe a shell script using xargs and curl? Maybe a simple Golang program? Go’s powerful concurrency features would work well for this.

Instead, I decided to try to use Rust. I’ve read a lot about safe concurrency in Rust, but I’ve never tried it. I also wanted…

Remote Ruby 

"Just Keep Hitting Tab"

Riding Rails 

This week in Rails - Rack 2.1 released, disallowed deprecations, and more!

Hello, this is Andrew, bringing you the latest news from the Ruby on Rails world!

18 contributors to Rails in past week

There have been 18 contributors to Rails in the second full week of 2020! 

Rack 2.1.0 and 2.1.1 released

These releases add support for the SameSite=None cookie value, new HTTP status codes, bug fixes, and several other exciting changes and additions. Updates to Rails following the release have also begun.

Check out the Rack changelog to learn more.

Introduce Active Support Disallowed Deprecations

This addition allows the configuration of rules to match deprecation warnings that should not be allowed and ActiveSupport::Deprecation#disallowed_behavior, which…

Vladimir Makarov – Red Hat Developer 

MIR: A lightweight JIT compiler project

For the past three years, I’ve been participating in adding just-in-time compilation (JIT) to CRuby. Now, CRuby has the method-based just-in-time compiler (MJIT), which improves performance for non-input/output-bound programs.

The most popular approach to implementing a JIT is to use LLVM or GCC JIT interfaces, like ORC or LibGCCJIT. GCC and LLVM developers spend huge effort to implement the optimizations reliably, effectively, and to work on a lot of targets. Using LLVM or GCC to implement JIT, we can just utilize these optimizations for free. Using the existing compilers was the only way to get JIT for CRuby in the short time before the Ruby 3.0 release, which has the goal of improving…

Andy Croll 

Be Suspicious of Join Tables

We often have to represent many-to-many relationships between models in our applications. Rails provides a method in its migrations to generate a table in your database to support this. You can see the documentation in the Rails guide for ActiveRecord migrations.

However, these basic join tables often obscure a useful concept in your application that might be better represented as a named model.

Instead of…

…using a join table:

Migration

create_join_table :user, :organisation

app/models/user.rb

class User < ApplicationRecord
  has_and_belongs_to_many :organisations
end

app/models/organisation.rb

class Organisation < ApplicationRecord
  has_and_belongs_to_many :users
end

Use

…a…

Alfredo Motta 

Not So Random Software #10 – The one about Automation

Welcome back to Not So Random Software. This week’s links are dedicated to Automation and how we can keep a healthy relationship with it. A random article or paper In an automated system two roles are left for the human operator; (a) monitoring that the automated system is working correctly, and (b) taking over control […]
The Life of a Radar 

Getting Started with Rails: Extended Edition

This guide is an extended edition of the offical Getting Started with Rails guide.

This extended version has the following additions:

  • A re-worked introduction to routing, showing clearer matching between routes and controllers.
  • Creates and uses a model right after building the first route.
  • Examples of HTML output generated by Rails helpers such as link_to, form_with and text_field.
  • Beef up explainations of routing helpers, especially article_comment_path.
  • Beef up explainations in general.

This guide covers getting up and running with Ruby on Rails.

After reading this guide, you will know:

  • How to install Rails, create a new Rails application, and connect your application to a database.
  • T…
Super Good Software 

Solidus v2.10 Released

There’s been some great development work done on Solidus since the v2.9 release. The community continues to do fantastic work and there’s a lot to show for it in this release.

Rails 6 Support

One of the big things that the new version brings is support for Rails 6. Rails 6 includes many great improvements including multiple database support, a big win for stores that are scaling up and facing database bottlenecks.

Solidus v2.10 also deprecates Rails 5.1 support. While this release still supports Rails 5.1, that version has hit its maintenance end-of-life and is no longer receiving security fixes. If you’re still running Rails 5.1 you should consider upgrading.

State Machine Customization

If…

Super Good Software 

Solidus v2.10 Released

There’s been some great development work done on Solidus since the v2.9 release. The community continues to do fantastic work and there’s a lot to show for it in this release.

Rails 6 Support

One of the big things that the new version brings is support for Rails 6. Rails 6 includes many great improvements including multiple database support, a big win for stores that are scaling up and facing database bottlenecks.

Solidus v2.10 also deprecates Rails 5.1 support. While this release still supports Rails 5.1, that version has hit its maintenance end-of-life and is no longer receiving security fixes. If you’re still running Rails 5.1 you should consider upgrading.

State Machine Customization

If…

Appfolio Engineering 

Symbol#to_s Returned a Frozen String in Ruby 2.7 previews - and Now It Doesn’t

How a Broken Interface Getting Fixed Showed Us That It's Broken

One of the things I love about Ruby is the way its language design gets attention from many directions and many points of view. A change in the Ruby language will often come from the JRuby side, such as this one proposed by Charles Nutter. Benoit Daloze (a.k.a. eregon), the now-lead of TruffleRuby is another major commenter. And of course, you’ll see CRuby-side folks including Matz, who is still Ruby’s primary language designer.

That bug has some interesting implications… So let’s talk about them a bit, and how an interface not being perfectly thought out at the beginning often means that fixing it later can have difficulties.…

Code with Jason 

Where to start with introducing TDD to a new Rails app

A Code With Jason reader recently wrote me with the following question:

How do I introduce TDD into a new Rails app? Where do I start? I am deeply knowledgable on RSpec and use it a lot. I am not sure how to get started with testing in Rails. When should testing be introduced? (hopefully as soon as possible) What should be testing vs. what should I assume works because it was tested in some other way? For example, why test generated code?

There are a lot of good questions here. I’ll pick a couple and address them individually.

How do I introduce TDD into a new Rails app?

This depends on your experience level with Rails and with testing.

I personally happen to be very experienced with both…

Ruby Conferences 'n' Camps in 2020 - What's Upcoming? 

Rails Camp West @ Diablo Lake, Washington, United States - Ruby Conferences 'n' Camps Update

Conferences 'n' Camps

What's News? What's Upcoming in 2020?

Rails Camp West
Sep/1-4 (4d) Tue-Fri @ Diablo Lake, Washington, United States • (Updates)

See all Conferences 'n' Camps in 2020».

Awesome Ruby Newsletter 

💎 Issue 191 - Pros and cons of using structure.sql in your Ruby on Rails application

Ruby Conferences 'n' Camps in 2020 - What's Upcoming? 

RubyConf Belarus (BY) @ Minsk, Belarus - Ruby Conferences 'n' Camps Update

Conferences 'n' Camps

What's News? What's Upcoming in 2020?

RubyConf Belarus (BY)
Apr/18 (1d) Sat @ Minsk, Belarus • (Updates)

See all Conferences 'n' Camps in 2020».

Ruby Weekly 

Using materialized views in Rails

#484 — January 16, 2020

Read on the Web

Ruby Weekly

Effectively Using Materialized Views in Rails — Postgres’s views and materialized views provide easy alternative ways of looking at a database’s underlying data through the lens of a persistent query, and working with them in Rails is not too tricky.

Leigh Halliday

A Migration Path to Bundler 2+ — If you’ve tried using Bundler 2, you probably know about the elevated RubyGems version requirements or other issues. Here’s a path the Bundler team could use (and has, partly.)

Benoit Daloze

Next-Gen Open Source Rails Commerce Platform — Workarea is…

Ruby on Rails Podcast 

303: Site Reliability at DEV with Molly Struve

Molly Struve is a Lead Site Reliability Engineer at DEV, the company that runs the blogging website dev.to. She and Brittany unpack what site reliability means, Molly's fondness of Elasticsearch and how Molly creates all of her witty and educational content.

Links for this episode:

Greater Than Code 

Fast & Furious with Penelope Phippen

Please enjoy this mini-episode of Greater Than Code featuring guest Penelope Phippen as we begin to pivot to our new podcast theme, the Fast & Furious. *

( * Just kidding, we are still a tech podcast.)

But we do hope you enjoy this set of outtakes where we grill Penelope on her Fast & Furious knowledge and speculate about the future of the franchise.)

This is the kind of content we normally release exclusively to our Patreon subscribers, but we didn't want to hoard such joy, so it's a gift to all of you. But if you want more content like this, an invite to our Slack group, AND an invite to the Fast & Furious party at Jamey's house, please support us on Patreon! *

( * That is…

Ruby Magic by AppSignal 

Pros and Cons of Using structure.sql in Your Ruby on Rails Application

In today’s post, we’ll cover the significant differences and benefits of using structure.sql versus the default schema.rb schema formats in your Ruby on Rails application. In a data-driven world, knowing how to exploit all of your database’s rich features can make the difference between a successful and unsuccessful enterprise.

After evincing the main differences between the two formats, we’ll outline how to switch to structure.sql and demonstrate how it can help with ensuring data integrity as well as database functionality that you might otherwise not be able to preserve.

In the post, I’ll give examples of a Rails app that makes use of structure.sql with a PostgreSQL database, but the…

Saeloun Blog 

Ruby 2.7 fixed the parsing for multiple assignment with `rescue` modifier

Rescue modifier

We can use rescue modifier, in inline mode to rescue from exceptions raised by the RHS expression and assign some value to variable.

num = 10
denominator = 0
result = num / denominator rescue 1 # evaluated as result = ((num/denominator) rescue 1)
=> 1
result
=> 1

Here, the RHS expression raises ZeroDivisionError and rescue returns 1 in case of exception and result is assigned the value 1.

Rescue modifier with multiple assignments

Before Ruby 2.7, the expression is evaluated differently from single assignment mode in case of multiple assignments mode.

def calculate(num1, num2)
  # calculation method raises an exception
  raise StandardError
end

res1, res2 =…
Saeloun Blog 

Webpacker is the new default in Rails 6

Rails 6 has added Webpacker as the default JavaScript compiler instead of Sprockets. Thus, all javascript code will be compiled with the help of webpack by default.

Before Rails 6

The JavaScript was compiled with Sprockets Rails by default and resided in app/assets/javascripts directory. Stubs would be created when using scaffold generators.

With Rails 5.1+, we could provide an option to use Webpacker as the compiler while creating a new rails application,

rails new myapp --webpack

Or to use it with existing Rails application,

# Gemfile
gem 'webpacker', '~> 4.x'

And then install it with the Rails application,

bundle
bundle exec rails webpacker:install

After Rails 6

When we…

Valentino Gagliardi 

Asynchronous tasks in Django with Django Q

Learn how to use Django Q, the task queue, with the Redis broker for offloading long running tasks in your Django applications.

Asynchronous tasks in Django with Django Q

Requirements

To follow along you’ll need:

  • an Heroku account if you want to use their Redis add-on
  • the Heroku CLI installed on your system
  • a newer version of Python, ideally 3.6 or 3.7
  • Git

Deployment on Heroku is optional, and you can use your own Redis instance if you’ve already got one locally.

Setting up the project

And now let’s get to work! To start off we’re going to create a new Python virtual environment alongside with a Django installation:

mkdir django-q-django && cd $_
python3 -m venv venv
source venv/bin/activate
pip install…
Greater Than Code 

165: Rubyfmt with Penelope Phippen

01:37 - Penelope’s Superpower: An extremely cursed knowledge of the Ruby programming language’s grammar.

03:09 - Writing Ruby Programming

05:50 - Why Penelope is Doing This the Way She Is

  • Were Any Bugs Found in the Ruby Grammar
  • There is No Spec
  • There is No Written Standard for How Ruby is Supposed to Work

07:32 - Inability to Extract Parse.y Out

  • Penelope’s Ideas

12:02 - What Problem Penelope is Trying to Solve With This Program

  • Rubocop Doesn’t Well Solve This Problem

18:30 - Hierarchy of Nitpicking

20:35 - Opportunities for Collaboration

22:44 - Major Challenges Faced

  • Finding Time
  • No Major Challenges
  • Community Overwhelmingly Welcoming
  • This is Not a Gem

25:58 -…

Justin Collins' Blugh 

Sanitizing, Escaping, and Encoding

“We need to sanitize this data” is a phrase I have heard too many times in the context of web security. It always makes me a little nervous.

The implication of the term “sanitize” is somehow cleaning the data or rendering it “safe”. But the details of how that safety is achieved are a little vague.

Often it means simply searching for a function containing sanitize and blindly using that function.

That is usually the wrong thing!

Injection Vulnerabilities

Injection vulnerabilities, including cross-site scripting, are a top category of web vulnerabilities.

The root cause of injection vulnerabilities is the mixing of code and data which is then handed to a parser (the browser, database…

rossta.net 

3 ways Webpack surprises web developers

When I first started working with Webpack, I didn't realize how under-prepared I was. I was tasked with integrating Webpack into a large Rails app and I made a lot of mistakes along the way. I assumed how things should behave based on my previous experience with the Rails asset pipeline. Many of these assumptions turned out to be wrong. This was frustrating and humbling.

And after spending the last month answering Webpack questions on StackOverflow, I've come across plenty of folks going through some of the same mental hurdles I've experienced. I came away with some perspective on what about Webpack most commonly trips up developers.

The intended audience for this post has a general…

All Ruby Podcasts by Devchat.tv 

RR 446: Development Environments

Today the panel is talking about their development environments and preferences. Most of them run on Macs, but they talk about other operating systems. They discuss some of the pros and cons of using Apple products. While Apple has conveniences to help you restore data, many of them have had issues with cabling and the fact that Macs are not easily extendable. They agree that the speed at which a development environment gets up and running is less about the hardware and more about how the environment is set up.

The conversation turns to which development platforms they are running. They discuss the value of Docker as a development environment. The panel compares the features of database…

The Bike Shed 

228: Friends and Food (George Brocklehurst)

On this week's episode, Steph is joined by George Brocklehurst, a Development Director in the NYC thoughtbot office. Steph and George chat about the variety of projects and technologies that caught their attention during thoughtbot's recent internal hackathon. They also dive into Gitsh, a dedicated shell for Git commands, as they chat about preferred git workflows and George shares his recent adventure in updating Gitsh to support tab completion.

Valentino Gagliardi 

JavaScript private class fields and the TypeScript private modifier

In this post we’ll shed some light on JavaScript private class fields and see how they compare to the TypeScript private modifier.

JavaScript private class fields and the TypeScript private modifier

JavaScript private class fields and the need for privacy

Historically JavaScript had no native mechanism for protecting variables from access, unless of course, the quintessential closure.

Closures are the foundation for a lot of private-like patterns in JavaScript like the popular module pattern. But after ECMAScript 2015 classes took over in recent years, developers felt the need for more control over classes member privacy.

The class field proposal (at the time of writing in stage 3) tries to solve the problem with the introduction of pri…

Scott Watermasysk 

Turbolinks and Eleventy (and Static Sites)

With Gatsby, I like the idea of using a React router to make transitioning from page to page as seamless (fast) as possible. However, I could not convince myself overhead, and the complexity of Gatsby was not worth the effort. In the end, I decided to use Eleventy.

Still, this got me thinking about alternative approaches. On my Rails apps, I use Turbolinks and decided to give it a shot on my blog (and my Origin template).

Setting it up takes just a couple of seconds, and it has worked flawlessly. Assuming you can keep all of your scripts in your HTML Head (and they do not change from page to page), you should be able to do the same with minimal effort (on just about any static site…

Getaround Engineering 

Writing JavaScript like it's 2020

JavaScript (JS) has long been criticized for being verbose and quirky. But the recent additions made to the language allow us to cope nicely with some of the debatable design decisions that were made and even benefit from a truly enjoyable development experience. In fact JS boasts a vast ecosystem, is present in a wide array of development use cases and is improved each and every year with excellent features.

In the following article we explore some of these great features that were added to the language with ES2019 and ES2020.

NB: The following list does not aim at being exhaustive but merely at describing some of the new stuff I am enthusiastic about. Additionally, most of these new…

On the Edge of Ruby 

A Migration Path to Bundler 2+

Bundler 2 did not arrive quietly. It was noticed by almost every CI build failing when running bundle install. As a result, it seems many still avoid Bundler 2 and just use Bundler 1. In this post, I present some ideas on how to get more people to use Bundler 2, and no longer need Bundler 1 which will not be maintained forever.

The RubyGems Requirement of Bundler 2

The original release of Bundler 2, which is version 2.0.0, required such a recent RubyGems version that none of the released Ruby versions had a recent enough RubyGems version shipped with them. Bundler 2 also requires Ruby 2.3+, and finally drops support for Ruby 1.8.

This RubyGems version requirement was quickly found as…

Alfredo Motta 

Not So Random Software #9 – The one about Anger Management

Welcome back to Not So Random Software. This week’s links are dedicated to Anger and our relation to it. As Seneca pointed out many years ago we often suffer more in imagination than in reality. Our response to feelings of anger make all the difference to what happens afterwards and our happiness. A random article […]
Riding Rails 

This week in Rails - Deprecations, bugfixes and improvements!

Hello, this is Greg, bringing you the latest news from the Ruby on Rails world!

38 contributors to Rails in past week

There have been 38 contributors to Rails in the first week of the year! 

Deprecate “primary” as a connection_specification_name for ActiveRecord::Base

This PR deprecates the use of the name “primary” as the connection_specification_name for ActiveRecord::Base in favor of using “ActiveRecord::Base” to avoid confusion as earlier the classname was used in any other case.

Deprecate using Range#include? to check the inclusion of a value in a date time range

The usage of the Range#include? method to check the inclusion of an argument in date-time with zone range is…

Kir Shatrov 

Contributing to Ruby MRI

I’ve recently worked on (so far) my biggest patch to Ruby MRI. While the changeset is only 50 lines of code it took me a few days and couple takes to figure out the right way to make getaddrinfo interrupt and fail fast when DNS is unhealthy.

It’s often unclear where to start when you’re about to contribute to some large codebase in C. This post is a collection of notes, mostly for myself, on how to contribute code to Ruby.

  • make is your best friend. For any project, usually I like to start from reading the Makefile, but Ruby is using autoconf to generate platform-dependent Makefile, so 1) at the start you don’t even have a Makefile 2) the generated one is not too readable. Still, learn…
Awesome Ruby Newsletter 

💎 Issue 190 - Important information about Plataformatec's Elixir and Ruby Open Source projects

Ruby Weekly 

Yes, we're still excited about Ruby 2.7

#483 — January 9, 2020

Read on the Web

Ruby Weekly

Ruby 2.7 Commentary from Two Ruby Core Team Members — Koichi Sasada (ko1) and Yusuke Endoh (mame) are employed full time by Cookpad Inc. to work on CRuby/MRI and a post they did in Japanese about all the new goodies in Ruby 2.7 has now been translated to English. There is a lot to enjoy here.. prepare a few cups of coffee.

ko1 and mame

The Ruby Reference (Now Updated for Ruby 2.7) — An attempt to bring together and extend core Ruby documentation for Ruby 2.7 in one place. This is a pretty neat resource to have to hand.

zverok

🤔 How Well Do You…

Ruby on Rails Podcast 

302: Ruby Autoformatter! with Penelope Phippen

Penelope Phippen makes Rubyfmt, and was previously a lead maintainer of the RSpec testing framework. She’s been writing Ruby for just about a decade, and still remembers 1.8.6. She and Brittany discuss Rspec, Ruby Central and her thoughts on the Ruby community.

Links for this episode:

Saeloun Blog 

Ruby 2.7 fixed the parsing for multiple assignment with `rescue` modifier

Rescue modifier

We can use rescue modifier, in inline mode to rescue from exceptions raised by the RHS expression and assign some value to variable.

num = 10
denominator = 0
result = num / denominator rescue 1 # evaluated as result = ((num/denominator) rescue 1)
=> 1
result
=> 1

Here, the RHS expression raises ZeroDivisionError and rescue returns 1 in case of exception and result is assigned the value 1.

Rescue modifier with multiple assignments

Before Ruby 2.7, the expression is evaluated differently from single assignment mode in case of multiple assignments mode.

def calculate(num1, num2)
  # calculation method raises an exception
  raise StandardError
end

res1, res2 =…
Mike Perham 

Faktory Enterprise

The best way to kick off 2020 is by shipping something massive for me: Faktory Enterprise.

Faktory is an open source, language-independent background job system. If you want to scale your business app to many millions of transactions per day, background jobs are the best way to do it. Celery, Bull, Sidekiq are all popular but they are limited to the one language they are written in (Python, JS and Ruby respectively). Faktory's advantage is that you can use it with any programming language; it makes a large, consistent feature set available to all of those languages.

What's Faktory Enterprise?

Faktory Enterprise is the most feature-rich version of the Faktory job system available. If…

Saeloun Blog 

Improving Database performance and overcoming common N+1 issues in Active Record using includes, preload, eager_load, pluck, select, exists?

The performance of our Rails application depends on many variables, and one of those variables is the number of queries executed for completing an action. The less the number of calls to the database, the less the memory allocations and subsequently less the duration to complete the operation.

One such problem is the N + 1 query problem. If we have two tables projects and commits and we load two projects and subsequently all their commits it makes 1 query to fetch the project and N queries to fetch the commits for each project. Since addition is commutative we can write 1 + N as N + 1.

# projects = Project.where(id: [1, 2])
> SELECT "projects".* FROM "projects" WHERE "projects"."id" IN…
Valentino Gagliardi 

FormData, the new formdata event, and HTML forms

Have you heard about the new formdata event?

It’s just a new DOM event, but every new addition to the web platform makes me always excited.

What is FormData?

Let’s clarify what is FormData before getting into more details. For those new to web development, HTML forms are able to emit events. This is a feature of almost any HTML element.

Consider the following form:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>HTML forms and JavaScript</title>
</head>
<body>
<form>
    <label for="name">Name</label>
    <input type="text" id="name" name="name" required>

    <label for="description">Short description</label>
    <input type="text"…
Saeloun Blog 

Ruby 2.7 deprecates Regexp#match and Regexp#match? with a nil argument

Before

Before Ruby 2.7, Regexp#match returns nil when nil argument is passed to it. Whereas Regexp#match? returns false with a nil argument.

name = nil
/^Ruby[a-zA-Z]*/.match(name)
=> nil

/^Ruby[a-zA-Z]*/.match?(name)
=> false

In Ruby 2.7

With Ruby 2.7, Regexp#match and Regexp#match? with a nil argument will display a warning.

name = nil
/^Ruby[a-zA-Z]*/.match(name)
warning: given argument is nil; this will raise a TypeError in the next release
=> nil
 
/^Ruby[a-zA-Z]*/.match?(name)
warning: given argument is nil; this will raise a TypeError in the next release
=> false

The plan is to make these methods raise TypeError in the next version i.e. Ruby 3.0.

The change is done in…

GoRails Screencasts 

How to use Dependency Injection in Ruby

Dependency Injection is a common technique for making your code more flexible and testable by removing strict dependencies upon other classes, modules, and other types of dependencies in your code
Saeloun Blog 

Ruby 2.7 reverts the deprecation of flip-flop operator

Flip-flop operator

Flip-flop operator is a range operator. It is used between two conditions inside a loop. It evaluates to true when first condition is true and continues with same truth value until the second condition evaluates to true. It then starts returning false after the second condition is met until the first condition evaluates to true again.

Example:

Suppose we want to write some conditions for a 10 minutes interval training where the person should run for 45 seconds and then take a break for 15 seconds. The code for the same with flip-fop operators will be as follows.

(1..600).each do |time|
    sleep 1
    puts (time % 60 == 1)..((time-45)%60 == 0) ?  "Run" : "Break"
end

Above code will print Run for 45 iterations and print Break for…

Hi, we're Arkency 

How to migrate large database tables without a headache

This is the story how we once migrated an in-house event store, that reached its limits, to Rails Event Store.

My client used to say that the reward you get for achieving success is having to deal with even more complexity afterwards.

That couldn’t be more true even if only applied to the ever-accumulating database tables when your venture gets traction. One very specific aspect of this success was reaching the count of several hundred millions domain events describing what happened in this business over time.

What do you do when you realize you made some mistakes in the past and have to change the schema of such humongous table? Do you know and trust your database engine well enough…

Greater Than Code 

164: Psychological Balance with Dr. Mireille Reece

01:14 - Mireille’s Superpower: Being just herself. The sense of respect around the individuality of every person.

02:30 - Being Different From Others is a Good Thing

05:59 - Our Brains and Empathy

11:15 - The Brain vs. The Mind

19:22 - Three Brains in One

21:51 - HPA Axis

23:06 - Overcoming Unconscious Impulses

26:56 - Affective Prosody

33:26 - Balancing…

The Official BigBinary Blog | BigBinary 

Rails Multiple Polymorphic Joins

Having polymorphic associations in Rails can be a hard nut to crack. It enforces restriction on joins association which makes it difficult to write complex queries.

Consider following architecture where Defects can be of InspectedTruck or InspectedTrailer associated polymorphically.

  class InspectedTruck
    has_many :defects, as: :associated_object
  end

  class InspectedTrailer
    has_many :defects, as: :associated_object
  end

  class Defect
    belongs_to :associated_object, polymorphic: true
  end

Finding defects for inspected trucks using joins will raise error.

  => Defect.joins(:associated_object).load
  ActiveRecord::EagerLoadPolymorphicError: Cannot eagerly load the polymo…

We need to write a raw sql INNER JOIN to fetch trucks with …

All Ruby Podcasts by Devchat.tv 

RR 445: Location Services with Mithun Dhar

Mithun leads development relations at HERE Technologies which specializes in building location services and location platforms. A lot of location is so seamlessly integrated we don’t even have to think about it, but it’s quite complex. He talks about how location services work, such as a ride-sharing app. He talks about some of the tools and data available from HERE Technologies for people who want to use location services. The panel discusses when to use services from companies like HERE and when you should try to do it on your own. Mithun talks about other ways HERE’s services can be utilized. The panel discusses how companies can get mapping so wrong, and Mithun talks about some of the…

Paweł U. | Ruby on Rails Web Development Consultant Full Stack Blog 

Inheritance and Abstract Class Pattern for Ruby on Rails Controllers

Inheritance is often frowned upon, because “You wanted a banana but got the whole jungle…“. In some scenarios, it can be a viable alternative to modules composition for sharing behavior. In this tutorial, I will describe a practical use case where using abstract base class pattern plays well with Ruby on Rails controllers layer.

Read on if you want to find out how to “write Java in Ruby”.

Theoretical example

Let’s have a look at a sample implementation of an abstract class using plain old Ruby objects:

class Fruit
  def initialize
    raise "Cannot initialize an abstract Fruit class"
  end

  def tasty?
    true
  end

  def eat
    puts "I'm eating a #{description}."
  end

  private
The Bike Shed 

227: Hacks and Cheats

On this week's episode, Chris and Steph discuss their recent holiday hackathon efforts building a game in Elm. They discuss their experiences with Elm and the broader prospects of using Elm in more production applications. They also discuss the new git subcommands "git switch" and "git restore", and round things out with a listener question concerning FactoryBot and "minimum viable factories".

Hix on Rails 

Ruby on Rails Action Mailer configuration

If you're looking for Ruby on Rails Action Mailer configuration then you are in the right place.

This tutorial explains how to configure Ruby on Rails in the production environment toward sending emails via Ruby on Rails Action Mailer integrated with the most popular email providers

Gmail, Amazon SES, Mailgun, SendGrid, and Mailchimp's Mandrill are the most popular choices for sending emails with Ruby on Rails.

Table of contents

RubyGuides 

How to Use Rails Helpers (Complete Guide)

What are helpers in Rails?

A helper is a method that is (mostly) used in your Rails views to share reusable code. Rails comes with a set of built-in helper methods.

One of these built-in helpers is time_ago_in_words.

Here’s an example:

time_ago_in_words(Time.now)
# "less than a minute"

time_ago_in_words(Time.now + 60)
# "1 minute"

time_ago_in_words(Time.now + 600)
# "10 minutes"

This method is helpful whenever you want to display time in this specific format.

Another Rails view helper is number_to_human.

Example:

number_to_human(10_000)
# "10 Thousand"

This is great when you want to take a number & print it as you would read it, which makes it feel more human.

You can find more…

Notes to self 

Ruby 2.7 pattern matching after 10 months of professional Elixir

As it’s a tradition, we got a new Ruby version on Christmas. This time we are getting pattern matching, a feature highly praised in other languages. After spending some time with Elixir last year I was curious how does Ruby’s pattern matching feel in the Ruby world and indeed how does it compare to Elixir’s?

Ruby 2.7 is adding a new case/in syntax to support pattern matching. This also tells us, that this (so far experimental) feature is only available for our case statements. Let’s look on some Ruby code and how Elixir case statement makes it cleaner with pattern matching. In the first example we want to find a name of a parent called Alice and only as long as the kid is a single…

Valentino Gagliardi 

How to create a Django project from a template

A Django project template is the natural solution when the default Django project format is not enough anymore. Learn how to make your own in this tutorial!

How to create a Django project from a template

What is a Django project template?

A rather obscure feature of Django is the ability to install a Django project starting from a template, that is, from a custom directory structure.

This is convenient when the default project format is not enough anymore (it isn’t as soon as you want to deploy in production, trust me), or when you reached the point where you repeat the same configurations over and over for a lot of projects.

A Django project template is nothing more than a pre-defined project with a custom…

Alfredo Motta 

Not So Random Software #8 – The one about Time

Welcome back to Not So Random Software. This week’s links are dedicated to Time and our relation to it. If you are anything like me you see time running faster and faster the more we get involved in our career; you need to build your strategy to not let the most precious asset in your […]
JetRockets 

Problem with download file in Google Chrome

Julia Evans 

PaperWM: tiled window management for GNOME

When I started using Linux on my personal computer, one of the first things I got excited about was tiny lightweight window managers, largely because my laptop at the time had 32MB of RAM and anything else was unusable.

Then I got into tiling window managers like xmonad! I could manage my windows with my keyboard! They were so fast! I could configure xmonad by writing a Haskell program! I could customize everything in all kinds of fun ways (like using dmenu as a launcher)! I used 3 or 4 different tiling window managers over the years and it was fun.

About 6 years ago I decided configuring my tiling window manager wasn’t fun for me anymore and switched to using the Ubuntu stock desktop…

Drifting Ruby Screencasts 

Like Relationships and Global ID

In this episode we create a Like/Unlike system where users can like posts and use Global ID to obfuscate IDs.
Gavin Miller 

Interview With A First Year Computer Science Student

It’s been almost 2 years since my last post. There have been good intentions of writing things but you can clearly see how that turned out. To get back on track, I’ve pulled out an interview that I did for a local computer science from … timestamp says Oct 2016. My thoughts have largely stayed the same so I’ll post it below.


Q: What is your title in your company?
A: Software Engineer 4

Q: What are your technical certifications?
A: Bachelor’s Degree in Computer Science from University of Manitoba

Q: What technical website do you follow?
A: Hackers News, Stackoverflow, reddit.com/r/netsec, reddit.com/r/ruby, troy hunt, krebs on security, schneier on security, thought works, thought works…

Riding Rails 

This week in Rails - The 2019 edition

Hello, this is Prathamesh bringing you first issue of This week in Rails of the new year and new decade.
In this issue, we will go over the major changes that happened last year to the Rails codebase.

Happy new year!

494 contributors to Rails in 2019

There have been 494 contributors to Rails in 2019. Wow, that’s a staggering number! Thank you all for making Rails better.

Rails 6.0 released

Rails 6 includes headline features such as parallel testing, multi database support, new Zeitwerk autoloader along with new frameworks added to the Rails family.

Two new frameworks added to Rails

Action Mailbox and Action Text made their way to the Rails codebase during the Rails 6 release. Action…

Rémi Mercier 

2019 - a year in review

Well, here we are. December has come and gone. Now is the time to look back on what happened last year - and to brew some mulled wine.

Taking care of my internet garden

After writing sporadically for years, I’ve been itching to write more. And so I did! What changed? Well, I learned how to build software and ship things. As it turns out, it’s easier to write about something you enjoy doing day in day out.

I also decided to write for my pleasure rather than for the whole build an audience nonsense. That’s why there are no analytics, no SEO optimization, no engagement hacks (and let me tell you that I know quite a lot about those) on my website.

Relaunching my own corner of the web would…

Valentino Gagliardi 

What’s an API, really? The elusive meaning of Application Programming Interface

A post of mine ignited a furious debate around the meaning of “API”. In this post I’d like to expand more on the subject and shed some light.

What's an API, really? The elusive meaning of application programming interface

A bit of backstory

I don’t like at all the “50 things you should know” kind of posts, but I thought I would make a gift to the community with my “27 Web Development Terms You Should Absolutely Know About”.

Long story short, I had the gut to say that document.querySelector() is an API. Here’s my original definition:

Native API: a native API is a built-in tool available by default in a programming environment. Speaking of browsers for example we say that document.querySelector() is an API for selecting HTML elements.

A reader…

Hix on Rails 

Ruby on Rails Active Storage AWS, GCP, and Azure config

In this Ruby on Rails tutorial, we are going to configure Ruby on Rails Active Storage module to work with Google Cloud Platform, Amazon AWS S3 Buckets, and Microsoft Azure Cloud.

Table of contents

Let us learn more about Ruby on Rails Active Storage.

What is Ruby on Rails Active Storage?

Ruby on Rails Active Storage is responsible for storing any files in the Ruby on Rails application and exposing them to Ruby on Rails application's Active Record objects.

Ruby on Rails Active Storage out of the box comes equipped with four different file storage options:

  • a local disk-based service, useful for development and testing,
  • G…

Greater Than Code 

163: Cause A Scene with Kim Crayton

01:24 - Kim’s Superpower: Being a Black Woman in Tech with a Strategy and a Platform.

02:21 - Continuously Validating Your Space as a Black Woman

  • Technical vs. Technology
  • Kamala Harris Suspending Her Campaign
  • Inclusion, Diversity, and Business Strategy

08:10 - The System was Built to Harm and Oppress Black Women

15:42 - The Only Power Black People Have is the Power Whiteness Has Given Them

  • Capitalism, Communism, Marxism, Socialism are Theories Rooted in White Supremacy

21:24 - White Feminism is Bullsh*t

  • Whit…
Appfolio Engineering 

Ruby 2.7.0's Rails Ruby Bench Speed is Unchanged from 2.6.0

As of the 25th of December, 2019 we have a released version of Ruby 2.7.0. As you can read in the title - it’s basically the same as 2.6.0.

The 2.7.0 series is remarkable in how little the speed has changed. Overall it has been very stable with very little change in performance. I’ve seen a tiny bit of drift in Rails Ruby Bench results, sometimes as much as 1%-2%, but no more.

The other significant news is also not news: JIT performance is nearly entirely unchanged for Rails apps from 2.6.0. I don’t recommend using CRuby’s MJIT for Rails, and neither does Takashi Kokubun, MJIT’s primary maintainer.

I have a lot of data files to this effect, but… The short version is that, when I run 150 trials…

Scott Watermasysk 

Ruby Pattern Matching aka Almost JavaScript Destructing

One of my favorite (modern) JavaScript features is destructuring. Ruby 2.7’s pattern matching makes this almost possible, but the lack of handling missing items makes it unusable for destructuring today.

Pattern matching is clearly marked as experimental. It sounds like this more about the syntax and performance than functionality. Proper destructuring would make working with JSON (and Ruby hashes in general) more enjoyable. Hopefully this becomes an option.

See: JavaScript Destructuring.

Valentino Gagliardi 

My personal collection of Python (and Django) recipes

“And now something completely different”: my personal, living collection of Python (and Django) recipes.

How to make an installable Python package

For a Python package to be installable the project should have a file named setup.py in the project root. setup.py should have a call to the setup function from setuptools which takes at least the following arguments:

from setuptools import setup

setup(
    name="tweeter",
    version="0.0.1",
    description="Tweet bot",
    author="You don't want to know",
    packages=["tweeter"],
    install_requires=["tweepy>=3.8.0"],
)
  • name is the package name, tweeter in my example
  • version is the package version
  • description is a short…
Ruby in Source Diving on Medium 

Ruby 2.7 NEWS: Commentary by Cookpad’s Full Time Ruby Comitters

Ruby 2.7 NEWS: Commentary by Cookpad’s Full Time Ruby Committers

We are Koichi Sasada (ko1) and Yusuke Endoh (mame) from Cookpad Inc. tech team. Cookpad sponsors us to work full time developing the Ruby interpreter (MRI: Matz Ruby Implementation).

Koichi Sasada (ko1) and Yusuke Endoh (mame)

We released a Japanese article “Ruby 2.7 NEWS explained by Ruby Professionals” when Ruby 2.7 was released on 25th Dec. 2019. This is an English translation of the article with help from Miles Woodroffe.

NEWS” is a text file that lists all new features and changes of the Ruby interpreter. Compared to a few years ago, we are making an effort to make the file easier to read, for example, by adding many examples. Some of the code in the article is…

Awesome Ruby Newsletter 

💎 Issue 189 - Comprehensive Ruby 2.7 changelog

Ruby Conferences 'n' Camps in 2020 - What's Upcoming? 

Birmingham on Rails @ Birmingham, Alabama, United States - Ruby Conferences 'n' Camps Update

Conferences 'n' Camps

What's News? What's Upcoming in 2020?

Birmingham on Rails
Jan/31 (1d) Fri @ Birmingham, Alabama, United States • (Updates)

See all Conferences 'n' Camps in 2020».

Andy Croll 

Year in Review 2019

A year of simplification.

January—February

The year kicked off with a two-day, snow-shoed, walk around a mountain in the French Alps. One of the major benefits of working at Propellernet is it’s institutional obsession with snow-based activities.

We (Gary, Jon, Jack & I) spent the walk wrestling with the future direction of CoverageBook. A discussion that would dominate 2019 for me.

March

One March evening I “performed” The Impermanece of Software at BytesConf a small, Brighton-based (mostly) front-end conference. Only a handful of other talks, but all terrific.

Went Go Karting as a team. Practice and qualifying were completely dry. Come race-time the heavens opened and the track was…

Ruby Weekly 

The Ruby 2.7 edition

#482 — January 2, 2020

Read on the Web

🎉 As expected, after over a year of development, Ruby 2.7 came out on Christmas Day complete with a variety of new features, tweaks, and the usual bug fixes. Enjoy this special round-up issue focused on the new release before we get back to usual service on January 9 😄
P.S. Be sure to check out the end of the issue to see my personal favorite 2.7 feature!

Ruby Weekly

Ruby 2.7.0 Released — What better place to start than the official news announcement? This post covers some of the new features briefly and provides download links to the source releases. Here’s the 2.7.0 tarball

Yui…

Ruby on Rails Podcast 

301: Episode 300 Celebration: Part 2

Brittany and Nick continue to celebrate Episode 300 of the podcast! In Part 2 of the episode, they discuss Brittany's topic for ParisRB, setting up and contributing to dev.to and imposter syndrome training with chess and BodyPUMP. Happy New Year!

Links for this episode:

Brought to you by:

Mirror Placement

Thinking about a new Ruby job in 2020? Mirror Placement (specifically Brian) is always here to listen, learn, connect and advise…

Hix on Rails 

Ruby Environment Management

An automated Ruby environment management is necessary for developers to easily work on multiple Ruby programs on the same machine.

In the Ruby community, there are two popular managers responsible for installing and maintaining multiple Ruby versions - RVM and Rbenv.

Table of contents

What is Ruby Environment Management?

If you are actively working on programs written in Ruby, at some point you are going to install multiple versions of the language on your system.

Ruby…

Prathamesh Sonpatki 

Being paranoid about user enumeration attack using Devise gem in Rails apps

I have used devise for authentication in all my Rails projects in last 7 years. But recently I came across a nifty feature provided by Devise – paranoid mode.

In our Rails application, we have ability to reset password by clicking on the "Forgot password" link using devise. If we enter user's email, we will get an error if the user is not present in the database.

But this message indicates that user with given email does not exist in database. One can keep trying with different email addresses to see which ones exist in database and which ones don't.

This is called user enumeration attack and is one of the top web attacks listed in OWASP https://www.owasp.org/index.php/Testing_for_User_Enumer…

Scott Watermasysk 

Ruby Literals

There are quite a few I was completely unaware of. Ruby still surprises me every day.

See: Ruby Literals You May Not Know

Hix on Rails 

Ruby on Rails Redis installation and configuration

In this tutorial, we'll go step by step through Ruby on Rails Redis installation and configuration.

Redis is a key-value database, and it is very much worth using in multiple scenarios when working with Ruby on Rails.

Table of contents

Let's start this Ruby on Rails Redis guide.

What is Redis?

Redis is a BSD licensed, in-memory data structure store. It is one of the most popular NoSQL choices among open-source options available.

On top of that, Redis is the most popular key-value database, and…

Julia Evans 

2019: Year in review

It’s the end of the year again! Here are a few things that happened in 2019. I wrote these in 2015, 2016, 2017, and 2018 too.

I have a business instead of a job!

The biggest change this year is that I left my job in August after working there for 5.5 years and now I don’t have a job! Now I have a business (wizard zines).

This has been exciting (I can do anything I want with my time! No rules! Wow!) and also disorienting (I can do anything I… want? Wait, what do I want to do exactly?). Obviously this is a good problem to have but it’s a big adjustment from the structure I had when I had a job.

My plan for now is to give myself a year (until August 2020) to see how this new way of…

All Ruby Podcasts by Devchat.tv 

RR 444: Rails Against the Machine

Brittany Martin, Lead Web Developer at the Pittsburgh Cultural Trust joins the panel today to talk about her talk "Rails Against The Machine". She has given this talk at Southeast Ruby, Rubyconf MY and Ruby on Ice.

Brittany Martin works for the Pittsburgh Cultural Trust as the nonprofit’s Lead Web Developer, where she is part of the team that develops, supports and maintains the Trust’s ticketing and festival web applications. She is a certified AWS Developer and the host of the 5by5 Ruby on Rails podcast. Under her alter-ego, Norma Skates, Brittany officiates roller derby for the Little Steel Derby Girls.

Her talk's elevator pitch is as follows: "What should a development team do when a…

The Bike Shed 

226: Bespoke Nonsense

On this week's episode, in celebration of the new year, Thom shares the 2019 blooper reel! Words are hard and here's the audio to prove it. Listen to all of the silly mishaps, goofs, and general nonsense captured in between the moments of "professional podcasting". Chris and Steph also reflect on their top themes of 2019 and discuss New Year Systems vs New Year Resolutions.

Hix on Rails 

Ruby on Rails testing: RSpec configuration

This is the ultimate, step by step Ruby on Rails guide to RSpec testing framework configuration in Ruby on Rails project.

Table of contents

Let's get started.

What is RSpec?

RSpec is the most popular Ruby on Rails testing framework according to Ruby on Rails community. It is also perfectly capable to test any Ruby-written code. RSpec organization repository is neatly organized into smaller parts, such as:

  • rspec, the main RSpec package,
  • rspec-core, the gem providing structure for writing executable examples and a customizable rspec command,
  • rspec-rails, RSpec package dedicated to testing Ruby on Rails applications,
  • rspec-mocks, RSpec gem that provides support for…

and then some more. It all builds up into a comprehensive, fully-featured Ruby…

Code with Jason 

Extracting a tidy PORO from a messy Active Record model

Skinny controller, fat model – the old best practice

In 2006 Jamis Buck wrote a famous post called Skinny Controller, Fat Model. In it Jamis observed that Rails developers often put too much logic in controllers, making the code harder to understand and to test than it needs to be.

“Skinny controllers, fat models” became a piece of accepted wisdom in the Rails community. I think it was a genuine step forward in the overall state of affairs.

The new best practice: skinny everything

But over time developers apparently came to a realization that while it’s better in certain ways to put bulky code in models than in controllers, the fatness, wherever you put it, is still kind of a problem.

Other…

EquiValent 

RSpec Rails controllers test examples

Here are some RSpec examples on how I like to test Ruby on Rails controllers

I’ll be adding more soon

How I use controller tests

In my opinion controller specs should touch multiple layers of functionality and serve as an integration tests. Test like this go hand in hand with testing with primitives philosophy

I agree that sometimes you need to do mocks and stubs but overkill will come kick you or your teammates in the nuts one day.

unit-test

Reason why I don’t use request specs for this is that’s is bit harder to debug why the tests failed.

So in nutshell:

  • I use Controller tests as pragmatic integration tests of multiple layers taht can cover 70% - 90% of the application
  • I use…
Code with Jason 

My top five Rails performance tips for performance noobs

Performance is a topic that’s widely discussed and also, sadly, widely misunderstood.

I’m going to share five performance tips that have worked well for me in my 9+ years of using Rails and even before that, since much of what’s here is technology-agnostic.

I want to add a caveat: I’ve never worked for a big B2C startup that has needed to scale to millions of users. I’ve worked mostly applications with modest user bases and modest performance requirements. Luckily, I imagine my career experiences are probably pretty similar to that of most Rails developers, so it’s highly likely that what has worked for me performance-wise will also worked for you.

If you already know the basics of…

Valentino Gagliardi 

TypeScript, event handlers in the DOM, and the this keyword

TL;DR: in TypeScript pass this as the first parameter to event handlers. Keep reading for the full story.

What is this in JavaScript?

this in JavaScript is a magic keyword for: “whichever object a given function runs in”. Consider the following object and its nested function:

const person = {
  name: "Jule",
  printName: function() {
    console.log(this.name);
  }
};

When I call person.printName(), this will point to the person object. this is everywhere in JavaScript and depending on the skill level developers simply decide to avoid it in fear of errors or embrace it 100%. I’m on the second group.

this is also convenient when working with event handlers in the DOM and…

Alfredo Motta 

Not So Random Software #7 – The one about Goal Setting

After last week’s reflection time, this week is about goal setting for the new year. Over the years I have found hundreds of strategies for doing this type of exercise and it’s easy to get lost; accept that it is a challenging problem to crack. For comparison, seemingly simple problems like the Traveling Salesman or […]
Valentino Gagliardi 

What does it mean “event-driven” in JavaScript and Node.js?

Just starting out with JavaScript and “event-driven” is all over the place? Worry not and keep reading to learn more!

What does it mean "event-driven" in JavaScript and Node.js?

Event-driven and publish-subscribe

Event-driven architectures build on a common pattern in software development known as publish-subscribe or observer pattern.

In an event-driven architecture there are at least two actors: the subject and the observer.

The subject is like an FM radio, it broadcasts a message to any observer interested in listening what the subject says.

What means "event-driven" in JavaScript and Node.js?

There could be just one or one hundred observers, it does not matter as long as the subject has some message to broadcast.

Keep in mind that event-driven, publish-subscribe, and…

Ruby • Hrvoje Šimić 

Deep dive into Did You Mean

Since version 2.3.0, Ruby comes bundled with did_you_mean, a handy gem for detecting typos.

Riding Rails 

Ruby 2.7.0, Rails 6.0.2.1 and more

Hello, this is Wojtek reporting on last month additions to Rails codebase.

Ruby 2.7.0 released

The last minor version of Ruby 2.7 before 3.0 release in the next year. Rails codebase is constantly updated to support Ruby 2.7 without any warnings.

Rails 6.0.2 released

Followed by security fix releases 5.2.4.1 and 6.0.2.1

Track Active Storage variants in the database

Optimization and bug fix by avoiding existence checks in the storage service.

Conditional values in Tag Builder

Handy addition to clean up common use case with constructing class names when creating content tags.

Add class_names view helper

As a follow-up to conditional values in Tag Builder, to ease even more…

Ruby Changes 

Ruby 2.7

Highlights:

Ruby 2.7 is a last major release before 3.0¹, so it introduces several important changes, larger in scale than previous releases (and also a bit lean on a “just nice to have” features side). Be prepared!

  • Pattern matching
  • “Real” keyword argument
  • Numbered block parameters
  • Beginless range
  • Enumerator.produce
  • GC.compact
  • Large update of IRB
  • Serious cleanup of the standard library

¹There is a possibility 2.8 will also be released, but in any case, Christmas release of 2020 is promised to be Ruby 3.0.

Read more »

Awesome Ruby Newsletter 

💎 Issue 188 - Ruby 2.7 pattern matching demo on YAML data

Julia Evans 

"server" is hard to define

Somebody asked me recently what a server was, and I had a harder time explaining it than I expected! I thought I was going to be able to give some kind of simple pithy answer but it kind of got away from me. So here’s an short exploration of what the word “server” can mean:

a server responds to requests

A server definitely responds to requests. A few examples:

webserver:

Me: "please give me google.com" 
Server: "here is the HTML for that webpage"

bittorrent server:

Me: "I would like this chunk of the good wife season 2"
Server: "here are some of the  bytes from that .avi file!"

mail server:

Me: "can you send this email to julia@jvns.ca"
Server: "I sent it!"

But what is a…

Prathamesh Sonpatki 

Managing warnings emitted by Ruby 2.7

Ruby 2.7 is released on Christmas 2019.

If you don't know what Ruby 2.7 offers, I have you covered.

I tried running codetriage on Ruby 2.7. When I run rails c it prints tons of warnings about various deprecations.

/Users/prathamesh/.rbenv/versions/2.7.0-rc2/lib/ruby/gems/2.7.0/gems/mustermann-1.0.3/lib/mustermann/regular.rb:22: warning: The called method `initialize' is defined here
/Users/prathamesh/.rbenv/versions/2.7.0-rc2/lib/ruby/gems/2.7.0/gems/sinatra-2.0.7/lib/sinatra/base.rb:1604: warning: The last argument is used as keyword parameters; maybe ** should be added to the call
/Users/prathamesh/.rbenv/versions/2.7.0-rc2/lib/ruby/gems/2.7.0/gems/sinatra-2.0.7/lib/sinatra/base.rb:1621:…
Ruby on Rails Podcast 

300: Episode 300 Celebration: Part 1

Brittany and Nick celebrate Episode 300 of the podcast! In Part 1 of the episode, they discuss New Years resolutions, switching back from Windows to MacOS and using Rubyfmt with Atom. A special thanks to you, the listeners, for helping make 300 episodes happen.

Links for this episode:

Brought to you by:

Mirror Placement

Thinking about a new Ruby job in 2020? Mirror Placement (specifically Brian) is always here to listen, learn, connect…

Valentino Gagliardi 

URL API: How to build an URL and its search parameters with JavaScript

Learn how to build, validate, and parse an URL with the URL API: a clean interface for building and validating URLs with JavaScript.

Getting to know the URL API

A lot of developers use regular expressions to validate and build URLs in JavaScript, and for good reasons.

But whenever I need to build one, the URL API is my friend. Keep in mind, it is not supported in IE, but works well on modern browsers, as well as in Node.js.

It offers URL validation out of the box and a nice API for working with search parameters. To create an URL call the constructor like so:

const myUrl = new URL("https://www.valentinog.com");

Where’s the validation you might ask. No worries,…

JetRockets 

Environment variables in NEXT js

Kir Shatrov 

Playing with BPF

I’ve been taking some time to study the BPF Performance Tools book by Brendan Gregg.

There’s a been a lot of partial resources and tips about using BPF, and it has already helped me to find an epic memory leak. I always wanted to get a chance to learn it deeper and the release of Gregg’s book was a good cause. My colleague from Shopify’s ProdEng team Dale Hamel helped to review the book too, which only pumped my interest about the technology.

When it comes to observability, the most impact (IMO) from being able to trace something really quickly and find the root cause is during incidents, when it’s not clear what’s happening and pulling the right observability tool from your hat is the…