Singularize edge case where it doesn't return to the correct singular #566

Closed
mort666 opened this Issue May 15, 2011 · 2 comments

Comments

Projects
None yet
3 participants
@mort666

mort666 commented May 15, 2011

It appears that singularize does't always return a plural to the correct singular.

While creating an app with the generator where the controller was called 'AreasOfAnalysis' it is correctly pluralized as 'AreasOfAnalyses', however I noticed that the generator had singularized variables as 'areas_of_analyasis'.

It worked fine, my model was called AreasOfAnalysis everything worked fine until I integrated the using library cancan to provide authorization, it appears to rely on singularize to recover the model name from the controller name.

Which results in the incorrect singular. As a result throws an 500 error for a missing constant. After tracking this down I noticed this could be down to the singularization of the controller name.

A quick test on the rails console confirmed, this is just pluralize and back

x = "AreasOfAnalysis".pluralize
=> "AreasOfAnalyses"
x.singularize
=> "AreasOfAnalyAsis"

This was to mimic the controller naming

x = "AreasOfAnalysis".pluralize.underscore
=> "areas_of_analyses"
x.singularize
=> "areas_of_analyasis"
x.singularize.camelize
=> "AreasOfAnalyasis"

This is in tested in Rails 3.0.7, also seems to affect earlier releases, tested with 2.3.5, 2.3.4 and 3.0.3

@josevalim

This comment has been minimized.

Show comment Hide comment
@josevalim

josevalim May 15, 2011

Contributor

Yeah, you need to add an inflection for it manually in your initializer.

Contributor

josevalim commented May 15, 2011

Yeah, you need to add an inflection for it manually in your initializer.

@josevalim josevalim closed this May 15, 2011

@chancancode

This comment has been minimized.

Show comment Hide comment
@chancancode

chancancode Jun 21, 2012

Member

@mort666 FYI, this is in fact a bug in the infector and it has been fixed in master. If you added an inflection rule to deal with this, you should be able to remove that when you upgrade to Rails 4.

Member

chancancode commented Jun 21, 2012

@mort666 FYI, this is in fact a bug in the infector and it has been fixed in master. If you added an inflection rule to deal with this, you should be able to remove that when you upgrade to Rails 4.

hisas pushed a commit to hisas/rails that referenced this issue May 9, 2017

hisas pushed a commit to hisas/rails that referenced this issue May 9, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment