avo icon indicating copy to clipboard operation
avo copied to clipboard

Respect inflection rules for record collections

Open sedubois opened this issue 1 year ago • 1 comments

Describe the bug

Avo does not seem to respect Rails' uncountable inflection rules.

Steps to Reproduce

  1. Create a Foo model and FooController
  2. Make foo non-pluralizable
# config/initializers/inflections.rb
ActiveSupport::Inflector.inflections(:en) do |inflect|
  inflect.uncountable %w(foo)
end
  1. create an Avo resource and controller for Foo: rails g avo:resource foo
  2. observe that "Foos" gets added to the side navigation menu

Expected behavior & Actual behavior

Name in side nav menu, index page & breadcrumbs should be "Foo" instead of "Foos".

System configuration

Avo version: 3.2.3

Rails version: 7.0.8

Ruby version: 3.2.2

License type:

  • [x] Community
  • [ ] Pro
  • [ ] Advanced

Are you using Avo monkey patches, overriding views or view components?

  • [ ] Yes. If so, please post code samples.
  • [x] No

Additional context

Reported as asked by Paul: https://discord.com/channels/740892036978442260/1193968080037085184/1194221025760645121

Impact

  • [ ] High impact (It makes my app un-usable.)
  • [ ] Medium impact (I'm annoyed, but I'll live.)
  • [x] Low impact (It's really a tiny thing that I could live with.)

I encountered this issue when trying out a singleton pattern, but currently I'm trying to move away from that towards something more CRUD-like, where the collection name is therefore plural.

Urgency

  • [ ] High urgency (I can't continue development without it.)
  • [ ] Medium urgency (I found a workaround, but I'd love to have it fixed.)
  • [x] Low urgency (It can wait. I just wanted you to know about it.)

sedubois avatar Jan 09 '24 10:01 sedubois

Approach

As we compute the name in the BaseResource.name and other methods, there's a disconnect between these two concepts (inflection and naming).

We can add a check and stop the pluralization.

adrianthedev avatar Jan 09 '24 11:01 adrianthedev