Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource Path Broken #4997

Closed
kvnlnt opened this issue Feb 10, 2012 · 7 comments
Closed

Resource Path Broken #4997

kvnlnt opened this issue Feb 10, 2012 · 7 comments

Comments

@kvnlnt
Copy link

kvnlnt commented Feb 10, 2012

I ran a scaffold with the name "Drive". All was well but I noticed the generated paths were "drife"...as in "new_drife_path" with an "F"!!!! I searched and replaced all instances of "drife" with "drive" and double checked my resources mapping, it's set to:

resources :drives

Even though I've changed any occurance of "drife" in my code and confirmed it's resource is correctly name a "rake routes" command still says "new_drife_path":

drive_index GET /drives(.:format) {:action=>"index", :controller=>"drives"}
POST /drives(.:format) {:action=>"create", :controller=>"drives"}
new_drife GET /drives/new(.:format) {:action=>"new", :controller=>"drives"}
edit_drife GET /drives/:id/edit(.:format) {:action=>"edit", :controller=>"drives"}
drive GET /drives/:id(.:format) {:action=>"show", :controller=>"drives"}
PUT /drives/:id(.:format) {:action=>"update", :controller=>"drives"}
DELETE /drives/:id(.:format) {:action=>"destroy", :controller=>"drives"}

Where in the heck are these paths being stored? I tried clearing every piece of cache i could think of...I even regenerated the controller...to no avail.

@fxn
Copy link
Member

fxn commented Feb 10, 2012

I created a scaffold using the stable version and everything looks fine. Which rails version are you using?

@pixeltrix
Copy link
Contributor

@fxn it's a inflector issue:

Loading development environment (Rails 3.2.1)
>> 'drives'.singularize
=> "drife"

@kvnlnt you can fix it in config/initializers/inflections.rb

ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'drive', 'drives'
end
Loading development environment (Rails 3.2.1)
>> 'drives'.singularize
=> "drive"

@fxn I think this may be one instance where the rule on inflection updates might be relaxed - I can't imagine anyone is relying on the drive -> drife mapping and it's a common word.

@kvnlnt
Copy link
Author

kvnlnt commented Feb 12, 2012

ahhhhhhh! Inflectors. Thanks pixeltrix. I'm obviously still learning Rails concepts. I really appreciate your help.

@kvnlnt kvnlnt closed this as completed Feb 12, 2012
@fxn
Copy link
Member

fxn commented Feb 12, 2012

But how did you get a scaffold with those routes? I am still curious about that.

@pixeltrix
Copy link
Contributor

I can reproduce like this:

$ rails new testapp
$ cd testapp
$ rails g scaffold Drive
$ rake routes
    drives GET    /drives(.:format)          drives#index
           POST   /drives(.:format)          drives#create
 new_drife GET    /drives/new(.:format)      drives#new
edit_drife GET    /drives/:id/edit(.:format) drives#edit
     drife GET    /drives/:id(.:format)      drives#show
           PUT    /drives/:id(.:format)      drives#update
           DELETE /drives/:id(.:format)      drives#destroy

This is with Rails 3.2.1 on Ruby 1.9.3.

@kvnlnt
Copy link
Author

kvnlnt commented Feb 12, 2012

yep...exactly what I encountered.. I ran a scaffold..got those routes, thought I messed something up and therefore tried again...and same result. Was all mystery until I discovered these "inflectors". Which pixeltrix confirmed (thanks again). You tricky rails, you tricky.

@rgaufman
Copy link

Was bitten by this today, I still don't understand how this makes sense:

1] pry(main)> 'drives'.singularize
=> "drife"

Why not drive? - what is the logic behind this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants