How to implement a Rails model called "series"?

Single and multiple forms are the same, and I get an undefined_method error when trying to apply the New method.

I understand why, and I know that the easiest solution would be to use a different name.

I also know that I can create a custom inflection, but what?

The problem is that I really need URLs like / series, / series / 1, etc., because I am actually modeling ... wait for it ... a series of events.

Using "set" or "sequence" or another synonym does not convey the intended value.

A series of events is a series that is not a plurality or sequence.

Is there a way to "alias" the model?

Should / can I use named routes?

Any help is appreciated.

+4
source share
3 answers

Assuming you used script/generate scaffold series to create a model controller, etc., you should have a line in /config/routes.rb, for example

 map.resources :series 

If you change it to

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

It will work. Or you can add an Eric Hill inflection initializer.

+1
source

So:

 class Series < ActiveRecord::Base ... end 

definitely not working? Looking at the source , a series is one of the rules for constructing unique images, and according to the โ€œPluralizer,โ€ you should be able to name the class of the Series model, as described above.

0
source

You should be able to do this exclusively with kinks. In config/initializers/inflections.rb :

 ActiveSupport::Inflector.inflections do |inflect| inflect.uncountable 'series' end 

Restart the application to activate.

0
source

Source: https://habr.com/ru/post/1300188/


All Articles