Introduction

The Lucky web framework takes some inspiration from Rails and has alot of magic. That is part of the reason why I really like the framework.

I recently had an issue with the way acronyms are pluralised (similar to my experience with Rails) and this post goes over the workaround.

The Issue

VRF is pluralised to vrves?????? Baby jesus help me please!!!

This excellent post contains most of the workaround and an excellent explaination so I won't repeat it here.

The Workaround

The first thing to do is add inflection rules in the config/infector.cr file.

file

# config/infector.cr
Wordsmith::Inflector.inflections.irregular("vrf", "vrfs")
    

Now if you use the resource generator, VRF will be singluar/pluralised correctly. That's not all though. If you stop there, you get the following error.

error

Unhandled exception: Vrf wants to use the 'vrves' table but it is missing.
    

Next, update the src/models/vrfs.cr file, explicitly naming the table :vrfs.

file

# src/models/vrfs.cr
class Vrf < BaseModel
  # table do
  # Add :vrfs here
  table :vrfs do
    column name : String
    column description : String
    column route_target : String
    column route_distinguisher : String
  end
end
    

Finally, restart the dev server and you will be golden.

Summary

In this post we added some inflection rules to correctly handle acronym pluralisation. Special shout out to Bill Tihen for the excellent post.

Tags

lucky crystal