This project is archived and is in readonly mode.

#684 ✓wontfix
Daniel Rice

NameError after creating scaffolding for object "Dive"

Reported by Daniel Rice | July 23rd, 2008 @ 07:45 PM | in 2.x

After creating a new Rails 2.1.0 app, naturally I create scaffolding for the models. I discovered while creating a site that a model named "Dive" does not work after creating the scaffolding. localhost:3000/dives errors with a NameError. new_dive_path does not exist? From app/views/dives/index.html.erb

Steps to reproduce:

1) Create a new rails 2.1.0 app.

2) script/generate scaffold dive name:string

3) create the necessary database in development environment (DB doesn't matter probably, i tested with sqlserver)

4) rake db:migrate

5) load the site, http://localhost:3000/dives

You should get the following error.

NameError in Dives#index

Showing dives/index.html.erb where line #20 raised:

undefined local variable or method `new_dive_path' for #

Extracted source (around line #20):

17:

18:

19:

20: <%= link_to 'New dive', new_dive_path %>

I can make this go away by simply changing the model name:

script/destroy scaffold dive

script/generate scaffold random name:string

I hypothesized that this had to do with the "ive" ending on words. To test, I create a similar scaffold "hive" and "thrive." Hive loaded just fine. Thrive did not.

Comments and changes to this ticket

  • Daniel Rice

    Daniel Rice July 23rd, 2008 @ 07:52 PM

    To workaround the issue, I have simply renamed the model to a non *ive word and used a route.rb redirect to get mysite/dives to work.

  • Jacek Becela

    Jacek Becela July 23rd, 2008 @ 08:03 PM

    It looks like some issue with Inflector. Maybe somewhere near "knife => knives"

  • Bob Showalter
  • Bob Showalter

    Bob Showalter August 7th, 2008 @ 03:23 PM

    • Tag set to patch

    Jacek is right; the problem is with the Inflector:

    $ script/console
    >> "dive".pluralize.singularize
    => "dife"
    

    The rules are a little too aggressive with the "ves" => "fe" conversion. "waves" -> "wafe", "stoves" -> "stofe", etc.

    The attached patch adjusts the rules to better match the general case and handles the above conversions correctly. Additional test cases added.

  • Bob Showalter

    Bob Showalter August 7th, 2008 @ 03:35 PM

    Hmm, I see from the rails core archives that the inflector is basically "frozen", so this patch may not be accepted.

    The rules can be applied locally if desired to handle some of the odd cases that the inflector doesn't handle well.

  • Daniel Rice

    Daniel Rice August 7th, 2008 @ 04:05 PM

    Hi Bob,

    I saw the diff file, but could you please post your patched inflector.rb to this ticket? I would like to try to give the patched inflector a try in my own environment since the workaround I have in place isn't ideal. If I run into any problems, I'll work on tweaking the regex's and post back my changes if any.

    If the inflector is "frozen" there might be a rails 2.2 release in the works or coming soon. That file should be patched to correctly work with English grammar eventually.

  • Bob Showalter

    Bob Showalter August 7th, 2008 @ 04:35 PM

    Daniel,

    Much safer for you to just run patch against my diff like this:

      patch < inflector_changes_for_ves.diff
    

    It will ask you which file you want to patch; just point to your inflections.rb.

    • Bob
  • Daniel Rice

    Daniel Rice August 7th, 2008 @ 04:46 PM

    Thanks Bob. I'm pretty new to RoR and haven't dug into the core very much at all. This is my first attempt at patching my own issue and digging into the rails source code.

    thanks for the update on this one for sure. I do appreciate the replies.

  • Daniel Rice

    Daniel Rice August 18th, 2008 @ 08:23 PM

    I added a manual fix to my projects configs\initializers\inflections.rb file instead of patching.

    configs\initializers\inflections.rb: Inflector.inflections do |inflect|

    inflect.plural 'dive', 'dives'
    inflect.singular 'dives', 'dive'
    

    end

    results in script\console doing this:

    "dive".pluralize.singularize => "dive"

  • Pratik

    Pratik August 21st, 2008 @ 04:42 PM

    • State changed from “new” to “wontfix”

    You should just define your own inflection rules.

    Thanks.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Tags

Pages