Mismatched routing in scaffold
reagleton opened this issue · 3 comments
I used the nifty:scaffold to generate a scaffold for my pre-existing Media model.
The scaffold generated the following paths (amongst others) as part of the scaffold,
- edit_media_path
- new_media_path
This caused a NameError
and when I checked rake routes
, I discovered that the RESTful resource routing had defined them as,
- edit_medium_path
- new_medium_path
From my explorations, it seems that Rails routing creates these paths based on the classify
method but that the Nifty scaffolding uses something else.
This may be a problem in Rails itself too because the form_for
method does not correctly identify the appropriate paths either when using the short form (as defined in http://guides.rubyonrails.org/form_helpers.html#relying-on-record-identification), but I would appreciate it if other more knowledgeable people could confirm that this is indeed a real issue (and that I'm not just forgetting something)
I ended up not only having to modify the paths of the scaffold but also have to add conditional code to the forms to assign the appropriate path and method.
Just as an update, I discovered that by editing config/initializers/inflections.rb
and adding the line below seems to have fixed the issue.
inflect.irregular 'media', 'media'
I would still like to know if anyone thinks this should be highlighted as an issue for either Nifty or Rails?
I think it's a Rails's default behavior, as the media
is treated as plural string.
'media'.singularize
=> "medium"
If you use rails generator, there would be a warning like this:
$ rails g scaffold media name
Plural version of the model detected, using singularized version. Override with --force-plural.
Modifying the inflections.rb
sounds ok to me.
I'm very late to the party, but what you want is to make "media" uncountable, and there is a method for that:
inflect.uncountable 'media'
So you don't repeat yourself with 'media', 'media'