Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Mismatched routing in scaffold #159

Open
reagleton opened this issue Dec 19, 2012 · 3 comments
Open

Mismatched routing in scaffold #159

reagleton opened this issue Dec 19, 2012 · 3 comments

Comments

@reagleton
Copy link

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.

@reagleton
Copy link
Author

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?

@kinopyo
Copy link

kinopyo commented Jan 25, 2013

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.

@leonelgalan
Copy link

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'

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

No branches or pull requests

3 participants