This week in #dev (Jul 14, 2023)

thoughtbot
Edited by Matheus Richard

Welcome to another edition of This Week in #dev, a series of posts where we bring some of the most interesting Slack conversations to the public.

finding multiple records by id

Elisa found out that you can pass an array of record ids to Active Record’s find method. It will return an array of model objects with those ids.

Neil added that if any of those ids don’t exist, Active Record will raise an ActiveRecord::RecordNotFound, just like it does with one single id.

VS Code: You might not need that extension

Matheus Richard talked about how Visual Studio Code sometimes adds new features that may make some extensions unnecessary. He shared a blog post that discusses some of those features.

Secure Tokens with Active Record

Summer ☀️ provided instructions on how to generate a random, unique key/token in an Active Record model using the has_secure_token method.

# Schema: User(token:string, auth_token:string)
class User < ActiveRecord::Base
  has_secure_token
  has_secure_token :auth_token, length: 36
end

user = User.new
user.save
user.token # => "pX27zsMN2ViQKta1bGfLmVJE"
user.auth_token # => "tU9bLuZseefXQ4yQxQo8wjtBvsAfPc78os6R"
user.regenerate_token # => true
user.regenerate_auth_token # => true

Easily Manage Multiple Heroku Accounts with CLI Extension

Fer shared a Heroku CLI extension that allows users to have multiple accounts set up and switch between them with a single command, making it easier to use multiple Heroku accounts in the terminal.

Thanks

This edition was brought to you by: Elisa Verna, Fer Perales, Matheus Richard, Neil Carvalho, and Summer ☀️. Thanks to all contributors! 🎉