Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I implement a Rails model named "series"?

The singular and plural forms are the same and I get an undefined_method error when trying to hit the New method.

I realize why and I'm aware that the easiest solution would be to use another name.

I'm also aware that I could create a custom inflection, but what?

The problem is that I REALLY need URLs like /series, /series/1 etc because I'm in fact modelling...wait for it...series of events.

Using "set" or "sequence" or some other synonym doesn't convey the intended meaning.

A series of events is a series not a set or sequence.

Is there a way to "alias" a model?

Should/can I use named routes?

Any help is appreciated.

like image 487
Danger Angell Avatar asked Feb 03 '10 15:02

Danger Angell


1 Answers

Assuming you used script/generate scaffold series to build your model controller et al, you should have a line in /config/routes.rb like

map.resources :series

If you change it to

map.series_index '/series',:controller=>'series',:action=>:index
map.resource :series

It will work. Or you could add Eric Hill's inflection initializer.

like image 191
BaroqueBobcat Avatar answered Oct 21 '22 02:10

BaroqueBobcat