Accounts

I hate the name “User” it means all and nothing. If you build blog system, what is user? A person who writes posts? Or maybe a person who writes comments? Could we name it Blogger? In a more complicated system probably we have more personas like that. In the current system, I don’t see a reason to have users, but it would be nice to have accounts where I can keep credentials for them....

July 29, 2023 · 3 min · Tobiasz Waszak

Track components changes

Currently, components could belong to bikes. But let’s say I have 3 chains and I rotate them every month. Or I have multiple wheelsets and I rotate them between multiple bikes. It would be super nice to track when something was mounted and when something is unmounted. One of the simplest solutions for that would be to create a table to make these connections. class CreateComponentAssignments < ActiveRecord::Migration[6.0] def change create_table :component_assignments do |t| t....

July 24, 2023 · 8 min · Tobiasz Waszak

New fields

Today is a small and boring topic. I decide to add more fields to my models. But since I decided to describe all my steps, I don’t want to skip anything. I created new migrations class AddMoreFieldsToBikes < ActiveRecord::Migration[7.0] def change add_column :bikes, :brand, :string add_column :bikes, :model, :string add_column :bikes, :weight, :float add_column :bikes, :notes, :text end end class AddMoreFieldsToBikes < ActiveRecord::Migration[7.0] def change add_column :bikes, :brand, :string add_column :bikes, :model, :string add_column :bikes, :weight, :float add_column :bikes, :notes, :text end end class RemoveDescriptionFromComponents < ActiveRecord::Migration[7....

July 18, 2023 · 1 min · Tobiasz Waszak

Models

Models in the context of an application’s business logic are objects that represent core entities and concepts. They encapsulate the data and behavior related to these entities and are usually persisted in some form of storage. In a typical Rails app, Active Record instances are often referred to as models. However, in this refactoring, we introduce a new Model layer that is distinct from Active Record and provides immutability. One key difference between Models and Active Record instances (Records) is that Models are immutable....

June 28, 2023 · 3 min · Tobiasz Waszak

Contracts

Contracts play a vital role in representing user-entered data within an application. They act as objects that encapsulate information available for modification, such as data from HTML forms or API payloads. When passed to repositories for persistence operations, contracts serve as the provided data from the app user. They possess knowledge about the expected attributes within a payload and enforce constraints to determine the validity of their own state. It is crucial to distinguish contracts from records....

June 27, 2023 · 3 min · Tobiasz Waszak