我对这个问题进行了一些调试,找到了一个可能更好的解决方案。
步骤1
在生成脚手架之前,请确保在您的 inflections.rb
文件中设置了正确的词形变化规则。
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'pokem', 'pokemon'
end
步骤二
现在您可以生成您的脚手架
[bruno ~/pokedex]$ script/generate scaffold pokem name:string
步骤三
查看您的新路由!
[bruno ~/pokedex]$ rake routes
pokemon GET /pokemon(.:format) {:controller=>"pokemon", :action=>"index"}
POST /pokemon(.:format) {:controller=>"pokemon", :action=>"create"}
new_pokem GET /pokemon/new(.:format) {:controller=>"pokemon", :action=>"new"}
edit_pokem GET /pokemon/:id/edit(.:format) {:controller=>"pokemon", :action=>"edit"}
pokem GET /pokemon/:id(.:format) {:controller=>"pokemon", :action=>"show"}
PUT /pokemon/:id(.:format) {:controller=>"pokemon", :action=>"update"}
DELETE /pokemon/:id(.:format) {:controller=>"pokemon", :action=>"destroy"}
注意
如果在定义单词形态之前生成脚手架,那么命名路由将不会更新。