Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] plural names generate a constant error

#3062

Greetings,

When I create a pre-plural-ized name with the scaffolding, I get an error like this:

-- start

NameError in PicturesController#index

uninitialized constant PicturesController::Pictures

-- end

Here are the steps to reproduce this problem:

-- START

rails test --database=mysql

cd test

rake db:create RAILS_ENV='development'

rake db:migrate

ruby script/generate scaffold user username:string

ruby script/generate scaffold pictures title:string

rake db:migrate

ruby script/server

-- END

http://localhost:3000/users -> this works.
http://localhost:3000/pictures -> this generates an const error.

OS: Ubuntu 9.04 "jaunty"
Ruby: 1.8.7 patchelevel 72
Rails: 2.3.3

--

If you need any more information, let me know.

-daniel

Reported by Daniel · August 16th, 2009 @ 11:50 PM

State: committed
Milestone: none
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: none

Activity

  1. John Pignata
    John Pignata

    +1 Verified -- it appears to be an issue where the assign_names! method is called during initialize but never reset in the event that the model name was plural. My patch resets assign_names! in this case and added an assertion.

    August 17th, 2009 @ 02:48 AM

  2. John Pignata
    John Pignata
    • Assigned user set to José Valim
    • Tag changed from auto, const, error, generated, plural, scaffold to 2-3-stable, auto, const, error, generated, master, plural, scaffold
    • Title changed from plural names generate a constant error to [PATCH] plural names generate a constant error

    Here's a patch for master. Currently, plural names passed as models to the scaffold generator in master don't generate any files but instead crashes due to a related bug.

    August 17th, 2009 @ 04:02 AM

  3. Kane
    Kane

    why do you think this should work?

    "Pass the name of the model (in singular form), either CamelCased or under_scored, as the first argument, and an optional list of attribute pairs."

    August 26th, 2009 @ 01:48 AM

  4. John Pignata
    John Pignata

    There's code in the generator now to handle the case when a plural name is passed - though it reports that it's reverting to singular it's simply not working:

        jp@populuxe:~/Projects/scratch/test_scaffold$ script/generate scaffold cars
         warning  Plural version of the model detected, using singularized version.  Override with --force-plural.
    

    August 26th, 2009 @ 02:08 AM

  5. Kane
  6. José Valim
    José Valim
    • Assigned user changed from José Valim to Jeremy Kemper

    Fixed on master, must be merged soon. Just need to apply the patch in 2.3 stable.

    August 30th, 2009 @ 04:40 PM

  7. Repository
  8. Repository
    Repository
    • State changed from new to committed

    (from [ff8cb50f25e426c531743fbf918e2a870e60e0e8]) Ensuring that a singular model name is set for use in controllers when scaffold is passed a plural model name

    [#3062 [PATCH] plural names generate a constant error state:committed]

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
    http://github.com/rails/rails/commit/ff8cb50f25e426c531743fbf918e2a...

    August 30th, 2009 @ 09:31 PM