Ognjen Regoje bio photo

Ognjen Regoje
But you can call me Oggy


I make things that run on the web (mostly).
More ABOUT me and my PROJECTS.

me@ognjen.io LinkedIn
Check out
The Marketplace Guide
A collection of lessons for the early stages of building a marketplace startup.
https://themarketplace.guide

#rails

2024

2021

Automatically creating plural models in Rails

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)

Functional model pattern

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)

How to get the direct path to a Webpacker pack

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... (119)

Rails pattern: state params

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)

Combining cached and live JSON in Rails

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)

Building human readable link building in Rails

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)

Filling a number field in cucumber tests

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)

Uploading a file in cucumber tests

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

Consistent display of dates in Rails

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)