PostgreSQL Upgrade and Database Restoration Guide To support the pgvector gem, I upgraded my local Postgres.app from v13 to v17 on macOS. Below is the full upgrade and restoration process for my project. Environment OS: macOS PostgreSQL: Upgraded f...
Introduction In Ruby on Rails applications, handling database transactions efficiently is crucial to maintaining data integrity. One common issue developers face is dealing with runtime errors caused by unpersisted changes when using the with_lock me...
It is common to see require 'something' in a Rails application. But what exactly does require do? What is require used for in Ruby? require is used to load external libraries or modules into your program. For example, Before you require the JSON modu...
In my daily job, I mainly use Rails framework. To make code readable and maintainable, we seldom write raw SQL in the codebase. Instead, we use Rails's ActiveRecord::QueryMethods module which helps developers write beautiful queries quickly. For exam...
Before implementing a new feature, I like to make sure what problems we are going to solve, why we should solve them, and how much time we can implement this feature. Here are 7 steps I usually do before I involve in a complex feature implementation....
Sometimes we will use klass_name.all to get records from the database. That’ll be ok, if we only have 100 records in the database. However, using klass_name.all might not be the best way to get records, especially when we need to query large numbers ...
Environment macOS Monterey (Version 12.1) Ruby 2.6.6 Ruby version manager: RVM Editor: VS Code To Reproduce: I've installed rubocop gem in my app and add an extension ruby-rubocop in my VS Code. Open VS Code and see the warning messages below. ...
Note: The following was tested with Ruby 2.6.6 Keyword: Heredoc What is heredoc? Heredoc is used for a form of multiline strings and preserves the line breaks and whitespace (including indentation) in the text. How to define a heredoc in Ruby? stri...
Note: The following was tested with PostgreSQL 13.1 Default setting: \x off $ psql myblog_dev myblog_dev=# SELECT "users".* FROM "users" WHERE "users"."role" = 10 LIMIT 1; The output format would be: It was difficult to read the result. Turn on th...
Rake is a task runner/task management tool in Ruby. You can create diverse tasks, put tasks in the Rakefile, and execute a command like rake :your_awesome_task. Your task will start running by Rake. In Ruby, you can put task code inside a file named ...
Recently, I had a job to fix the slow code. Before diving into fixing the slow code, I used Scout APM to identify the performance bottlenecks, which helped me make sure where the slow code is. To prove the new optimization solution is faster, in addi...
Note: The following was tested with Ruby 2.6.6 / Rails 5.2.6. Situation I tried to add an environment variable in the application.yml file. # config/application.yml default: #... API_TOKEN: ABC123456 And I expected when executing ENV['API_TOKEN...
When we would like to sort the result-set in ascending or descending, we can use ORDER BY in SQL query. In Rails, we can use order which is derived from ActiveRecord::QueryMethods. For example, Article.all.order(published_at: :desc) Let's focus on t...
What's AJAX? AJAX (Asynchronous Javascript and XML) is a kind of technique that can send HTTP requests and exchange data with a server by Javascript. It's an important and practical technique to enhance the user experience, especially when we want to...
What's nil? nil is an instance of NilClass. It's a special Ruby object used to represent the absence of any value. And it also behaves like false when used in a conditional statement. What's more, there is only one nil object, whose object_id is alwa...
Recently, I start reading Practicing Rails. I love the main point in chapter 1: Rails console is a good place to experiment with our ideas. There are 3 tips to explore ideas through the Rails console I learned from Practicing Rails. 1. Use app object...
It's common to see a before_action method that need executing in different controller actions. At the same time, when writing RSpec tests for these actions, it's easily to write down context blocks whose test examples are almost the same, and only a ...
When we develop a new feature, it's common to add a new column that needs some validations in the model. So, we might write something like this: class Book < ApplicationRecord #... validates :barcode, presence: true end To increase the test cove...
To Reproduce: git cm 'some_message' commit successfully, but git showed the message below: error: The last gc run reported the following. Please correct the root cause and remove gc.log. Automatic cleanup will not be performed until the file is r...