This project is archived and is in readonly mode.

#5987 ✓invalid
Philip Nelson

RoutingError (No Route Matches) after adding irregular inflector

Reported by Philip Nelson | November 16th, 2010 @ 05:39 PM

Using Rails 3.0.x (tested on 3.0.2 and 3.0.3)

I have a project which has an irregular plural : it requires an Aircraft model.

So added the following to config/environment.rb

ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'aircraft', 'aircraft' end

Then generated the scaffold for aircraft and began testing. Everything is fine when I access URLs such as http://localhost:3000/aircraft or http:/localhost:3000/aircraft/1.

But I created an index page (main/index) which has the following code in the view -

<%= link_to "Aircraft", aircraft_path %>

I then made this the default page for the app. When I then access this I get the following error -

ActionController::RoutingError in Main#index

Showing /home/philip/aircode/app/views/main/index.html.erb where line #3 raised:

No route matches {:controller=>"aircraft", :action=>"destroy"}

Extracted source (around line #3):

1:

Main#index


2:


3: <%= link_to "Aircraft", aircraft_path %>
4:

Rails.root: /home/philip/aircode

When I generate exactly the same app without the inflector code, and use -

<%= link_to "Aircraft", aircrafts_path %>

then everything is fine.

I attach two tarballs : aircode has the inflector and fails. airtest does not and works. Although these have ibm_db as the database driver in database.yml, I have also tested this using Sqlite3 with the same result.

Comments and changes to this ticket

  • Aditya Sanghi

    Aditya Sanghi November 16th, 2010 @ 09:50 PM

    • Importance changed from “” to “Low”

    run rake routes to see the routes created for your app.

    I assume if you have this irregular noun aircraft set with the same plural and singular word, rails would generate routes something like this --

    aircraft_index GET    /aircraft(.:format)          {:action=>"index", :controller=>"aircraft"}
                   POST   /aircraft(.:format)          {:action=>"create", :controller=>"aircraft"}
      new_aircraft GET    /aircraft/new(.:format)      {:action=>"new", :controller=>"aircraft"}
     edit_aircraft GET    /aircraft/:id/edit(.:format) {:action=>"edit", :controller=>"aircraft"}
          aircraft GET    /aircraft/:id(.:format)      {:action=>"show", :controller=>"aircraft"}
                   PUT    /aircraft/:id(.:format)      {:action=>"update", :controller=>"aircraft"}
                   DELETE /aircraft/:id(.:format)      {:action=>"destroy", :controller=>"aircraft"}
    

    On line 3, you would need to use the link as

      <%= link_to("Aircraft", aircraft_index_path) %>
    

    You would get this problem if you added the inflection after the scaffolding.

  • Santiago Pastorino

    Santiago Pastorino November 16th, 2010 @ 11:33 PM

    • State changed from “new” to “invalid”

    When the singular is equals to the plural we need to append _index at the end to differentiate from the helper which returns the GET for the SHOW. So what Aditya said is right ...

    https://github.com/rails/rails/blob/08c64bbd390d1ba6b44d29c5892693e...

  • Philip Nelson

    Philip Nelson November 17th, 2010 @ 09:07 AM

    I managed to work this out last night, when I realized while reading the routing section of AWDWR that following the standard pattern for named paths would result in a clash of names. I'm glad that they thought of this already, and indeed changing to application as suggested does make it work.

    What does concern me, and I often find this with Rails, is that the error messages you receive really don't give you any clue as to what the real cause of the problem is. it is the one thing about the Rails framework which I find challenging. It is all very well having all the Rails goodness, but if when you make a mistake you get such cryptic messages it means you lose a lot of the momentum. I guess many of these things come with experience ... hence the reason my bookshelf (both paper and electronic) is becoming full of books on Ruby, Rails, AJAX, etc.

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>

Attachments

Pages