The original Github issue is 
here: https://github.com/rails/rails/issues/6809, moving the discussion 
here per Steve's suggestion.

Long story short:

   1. The resource (and hence scaffold) generator currently automatically 
   detects and fix plural names for you
   2. Confusingly, the model generator does no such check and will happily 
   create plural models for you
   3. This is a common mistake that people make, especially confusing and 
   frustrating for newbies (I volunteered for RailsBridge and introduced 
   plenty of new devs to Rails). When they do that, a) they probably won't 
   notice the mistake; b) even if they do, they probably won't know how to fix 
   it quickly (end up renaming the filenames and the content by hand, which of 
   course usually generate far more errors)
   4. I myself make that mistake all the time... Somehow I can never 
   remember what the generators expect
   5. Even the pros make this mistake occasionally. Aaron famously did that 
   while recording the peepcode screencast :P

This is probably one of the most annoying things about Rails and I'd love 
to see it fixed.

If no one else is gonna do this, I'm willing to spend some time and come up 
with a PR. However there are a few complications:

1. Previously, String#singularize is not idempotent. The classic example is 
'address' 
=> 'addres'. This bug was fixed in 
#4719<https://github.com/rails/rails/issues/4719>, 
so this should no longer be a problem.

2. I'm not sure how NamedBase is supposed to work. From what I understand, 
the "name" parameter is assumed to be singular. I traced all the way back 
to the original 
implementation<https://github.com/rails/rails/blob/83f7fe2028df15e058205c93308c0e19abd7157a/railties/lib/generator/named_base.rb#L56-57>,
 
and it appears that the plural name is always pluralized explicitly while 
the singular name is more or less directly taken from the name parameter. 
(I am guessing this might have something to do with the bug I mentioned 
earlier.@josevalim <https://github.com/josevalim>?) This seems wrong to me 
as it is clearly not how it is being used now (e.g. the resource generator 
passes in a plural name here when creating the controllers). Even if it's 
not wrong the naming makes it extremely confusing.

3. I'm not sure where I should implement the check. (NamedBase is probably 
not a good place to put that logic as it will probably break a lot of 
generators out there.) Perhaps I should move 
this<https://github.com/rails/rails/blob/master/railties/lib/rails/generators/resource_helpers.rb#L20-27>
 to 
railties/lib/rails/generators/rails/model/model_generator.rb? Would that 
work?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-core/-/eM_2DoU8_A0J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to