Ruby on Rails Monday, July 10, 2017

I'm going to try to answer my own question.

I tracked down this answer:
https://stackoverflow.com/questions/23819312/rails-undefined-method-user-index-pathEnter code here.

The most important sentence tompave wrote in https://stackoverflow.com/questions/23819312/rails-undefined-method-user-index-path is this:

A model with a plural name, e.g. class Users, will confuse rails.


Analysis:


I was following along on
https://code.tutsplus.com/tutorials/authorization-with-pundit--cms-28202

And one can find there
rails generate scaffold Articles title:string body:text

This generates a warning

[WARNING] The model name 'Articles' was recognized as a plural, using the singular 'Article' instead. Override with --force-plural or setup custom inflection rules for this noun before running the generator.

The second most important sentence in tompave's answer is
Normally it would be user_path for singular routes (show, update, delete) and users_path for the plural ones (index, create). Here, however, users_path must be used for the singular routes, and Rails will fallback to use users_index_path for index and create.

The person who coded up the Rspec test seems to have known using the plural form "Articles" would generate the articles_index_path method rather than article_path.

And thus my confusion has been addressed.

I wish I could thank tompave directly

 



--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/7af92c34-b723-4839-ad0b-8b34c483de9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment