2021
December 21, 2021
At times it's more readable to use the plural of a model instead of singular. For instance Products.for_indexing
instead of Product.for_indexing
. This can be accomplished through a simple initializer that creates the plural model automatically.
(315)
December 21, 2021
My answer to an Ask HN. Use the db-updates-as-code for your framework, make the system fudgeable and have an audit log.
(118)
December 06, 2021
Similar to the actor model pattern, the functional model pattern creates multiple models that operate on the same table. But instead of focusing on the user type that primarily accesses it, it focuses on the functionality required. It works well for different stages of a base model.
(685)
May 13, 2021
How to get all the methods in Rails controllers, models and services
(155)
March 19, 2021
:after and specifically classes can be populated with user-specific content using CSS so that cached elements don't have to be duplicated for minor variations.
(725)
March 18, 2021
If you are making use of a serviceworker to cache JS or CSS or you’re rendering some JS server-side you have to have the full path to the file.If, at the same time, you’re using...
(111)
March 12, 2021
This improves readability especially for scopes that are very feature specific
(342)
March 09, 2021
I make use of the rails_amp gem in the affiliate site. It generates AMP from normal views.One of it’s features is automatically converting the image_tag into the AMP compatible ...
(254)
March 21, 2020
A useful pattern that I didn’t see documented before is what I call “state params”: returning different permitted params based on the state of the record.If there is an order mo...
(180)
March 21, 2020
In the course of doing upgrades for an older project I’ve discovered that not every activerecord version is compatible with every mysql2 version. The adapters use ~> to lock ...
(147)
February 11, 2020
They don't seem to be worth it
(185)
February 07, 2020
Very useful sort in scenarios where context is tied to a date
(437)
November 16, 2019
Had a scenario for the Supplybunny API where an endpoint needed to return a combination of live and cached data.The cached part was already in use in a few places. The new endpo...
(132)
October 02, 2019
A while ago I was working on the audit log and wanted to store both the user and the name. That way the name remains and can be shown if the user is deleted. The audited gem sto...
(178)
August 04, 2017
I’ve had this in my notes for a long time. In order to not upload files to your public/ folder, which is the default for carrier wave, it’s really simple. Just need to change a ...
(282)
May 16, 2017
A pretty neat thing I realized while building the search for Supplybunny is that you can use the results from elastic search to generate the cache keys that rails generates.The ...
(456)
April 28, 2017
A while ago I needed to improve the canonical links for some of our pages, specifically because we added more search parameters etc. so I made use of routes file to create some ...
(445)
March 31, 2017
It sounds so obvious when spelled out but you can use multiple timestamps in Rails models that each individually can serve as cache keys for different views. For example say you...
(641)
March 02, 2017
Split config accepts a host string directly as well as an instance of Redis. Therefore, we can use Redis to connect split to a password protected redis server. # config/initali...
(74)
February 28, 2017
In order to retry an inbound message that timed out, take a look at thePostmarkapp API documentation here.First, we need to get the server API token that can be found on the cre...
(101)
February 28, 2017
In order to upload a file in a cucumber test, that is to use a file select input, define the following in your user_steps.rb: Then(/^I fill in number field "(.*?)" with "(.*?)"...
(75)
February 26, 2017
In order to upload a file in a cucumber test, that is to use a file select input, define the following in your user_steps.rb: And(/^I attach "(.*?)" to "(.*?)"$/) do |field, fi...
(67)
2016
October 19, 2016
In order to consistently display dates in a Rails application the strftime format can be set globally.#config/initializers/time_formats.rbDate::DATE_FORMATS[:default] = "%d/%m/%...
(59)
September 21, 2016
To count the number of elements that is in a jQuery nested attributes container we can extend the plugin to have the following method (coffeescript): itemCount: -> @$item...
(86)
September 07, 2016
Occasionally you’d need to have a user who’s not registered preform an action and only enter their email address the result of which creates an account. For example when you wan...
(236)