Here are the steps I did. In command开发者_如何学运维 line:
rails new lcdemo rails generate scaffold Cove title:string
(created an entry in seeds.rb)
rake db:migrate rake db:seed
In the controller and view files, instance variables are named cofe instead of cove.
The reason
"cove".pluralize
=> "coves"
"coves".singularize
=> "cofe"
The solution
You can edit your config/initializers/inflections.rb file to create a custom inflection to teach Rails that the singular of "coves" is "cove".
inflect.irregular 'cove', 'coves'
That'll be the Inflector working its magic. It looks like it's pluralizing "Cove" to "coves" in order to make the table name, and then singularizing "coves" (by analogy with "wolves", "knives" etc) to "cofe".
I don't know if it'll work, but you could try adding the following to config/initializers/inflections.rb
before you run the scaffold generator?
inflect.plural "cove", "coves"
inflect.singular "coves", "cove"
精彩评论