Posts

  • Defining primary and foreign keys in Active Record associations

    In one of my Rails 4 projects, I found that it was easier to use the source database’s primary and foreign keys. The source database would drop and reuse keys without leaving a history of changes. Fortunately, Active Record makes it easy to change the keys used by the associations.

  • Connecting to SQL Server from PostgreSQL

    Foreign data wrappers enable PostgreSQL to access remote SQL databases. I use TDS foreign data wrapper (tds_fdw on GitHub) to connect PostgreSQL, serving as the Rails database, to a number of remote Microsoft SQL Server databases.

  • Finding Word Squares

    I completed a Ruby challenge to find word squares. A (perfect) word square is formed from a group words such that if you arrange them in a square, the same words can be read vertically and horizontally. I used a trie and recursion in my solution.

  • Using Vagrant for Ruby on Rails development

    I recently spent time developing a toy Rails 5 app using a Vagrant box. One of my goals is to avoid updating Homebrew. I experienced issues after updates, and had to spend evenings fixing package issues and OpenSSL problems.

  • Rendering Engine Partials on the Main App

    As part of the dashboard feature of a web app, I needed to render partials that provide an overview or summary for a particular business area (implemented as an engine). I could hardcode the render calls, but because the engines share common functionality or characteristics, I was able to use a helper function to test a particular partial’s existence and render it accordingly.

  • Pagination for Ransack Forms

    For pagination to work, you’ll need to submit the desired page number along with the search conditions. In this post, I will discuss how to add pagination for Ransack forms that use the POST method.

  • Running Sidekiq as a Linux Service

    I created a service to manage a single Sidekiq process. Below is my configuration that worked on RedHat Linux 7 using systemd. It is based on this example, and should work on CentOS as well.

  • Routes in Rails Engines

    My team uses engines because they add functionality in a modular way, and help us avoid the issues that come with bloated models (too many associations or methods) or deeply nested namespaces. In this post, I discuss some tips around engine routes.

  • Testing Concerns with RSpec

    For an overview, look at this StackOverflow post and then head over to the official RSpec documentation on shared examples. The best option seems to be testing concerns together with the models that include them. This post summarizes the approach I took in testing concerns on a recent project.

  • Form Objects and Nesting with Cocoon

    I created a Form Object (a Ruby class that inherits from ActiveModel::Model) to add multiple records using a single form. I used Sam Slotsky’s Dynamically add nested forms post as a basis for my solution, but I wanted Cocoon to handle form nesting for my Rails 4.2 app.

  • Understanding the Advanced Ransack Demo

    I keep forgetting how the advanced mode in this demo works, so I end up reviewing the source code every time I need to refresh my memory.

  • Issues with GitHub Pages and Jekyll

    Configuring Jekyll for GitHub Pages took longer than expected. Instead of linking to Jekyll’s quick start guide, Pages should have pointed me to its set-up instructions for local Jekyll installations.

subscribe via RSS