More on odd controller names

Posted by joakimk, Fri May 30 03:21:00 UTC 2008

Like I wrote in my previous post I had some problems using a model name that is the same in plural as singular. I just discovered this does not only apply to make resourceful, but also Rails (2.0.2) itself.

If you use news as the model name, then form_for(@news) in the view for the new action will fail to generate with this nice little error:
news_url failed to generate from {:controller=>"news",
                                  :action=>"show"} 

- you may have ambiguous routes, or you may need to
supply additional parameters for this route.
content_url has the following required parameters:
["news", :id] - are they all satisfied?

I haven’t delved too deep into form_for, but the problem seems to be within apply_form_for_options.

The moral of the story is… use model names that are spelled differently when in singular or plural form. To avoid this problem I’ve switched from using news to newsitem in my application.

Filed Under: | Tags:

Comments

Have your say

A name is required. You may use HTML in your comments.