0

So i've looked around and don't see a built in way to handle words that are named weirdly in the english language.

I have a Quiz model, which means that i have an index action of \quizes.

resources 'quizes', only: ['index', 'new', 'show']  

I would like to be able to do things like

quizes_path #Note this one works
quiz_path(:id) #this does not

I have to do quize_path(:id)

Here is the rake routes, notice that the path names are quize instead of quiz.

              quizes GET    /quizes(.:format)              quizes#index
           new_quize GET    /quizes/new(.:format)          quizes#new
               quize GET    /quizes/:id(.:format)          quizes#show

This is more for learning. I know i could just manually specify the singular resources and be done.

The ultimate question, is there a way to specify this in resources so that it knows that the singluar resources should remove 'es' instead of just 's'

EDIT

Here is the correct inflector based on the resources. Thanks!

ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.singular /^(quiz)es/i, '\1' end

Austio
  • 5,939
  • 20
  • 34

2 Answers2

2

Use quizzes instead of quizes in your route definition:

resources :quizzes

Then the singular routes are:

    new_quiz GET    /quizzes/new(.:format)       quizzes#new
   edit_quiz GET    /quizzes/:id/edit(.:format)  quizzes#edit
        quiz GET    /quizzes/:id(.:format)       quizzes#show
Anand
  • 3,690
  • 4
  • 33
  • 64
1

As @Anand's answer says you need to spell "quizzes" correctly in this instance. To answer your general question you're looking for inflections in the file config/initializers/inflections.rb. This has been asked before: Ruby on Rails Inflection Issue and Ruby on Rails: How do you explicitly define plural names and singular names in Rails? as examples.

Community
  • 1
  • 1
Michael Chaney
  • 2,911
  • 19
  • 26