我创建了一个名为pais的脚手架(这是巴西葡萄牙语中的一个词,与该国家相同),我使用以下命令创建:
ruby script\generate scaffold pais name:string abreviattion:string
首先,我将变形改为我当地的习语,就像那样:
inflect.plural /^([a-zA-z]*)s$/i, '\1ses' #The plural of Pais is Paises
当我试图在http://localhost:3000/paises上打开页面时,我收到了以下错误:
undefined method `edit_pais_path' for #<ActionView::Base:0x387fdf4>
提前致谢。
答案 0 :(得分:3)
"pais".pluralize
会产生"pais"
这对于选择制作News
模型的人来说非常常见。 Rails需要区分模型的单数和复数版本。
map.resources :pais, :singular => :pai
pai_path
,edit_pai_path
和new_pai_path
map.resources :pais, :as => "goats"
将为您生成这些路径:
HTTP URL controller action
GET /goats Pais index
GET /goats/new Pais new
POST /goats Pais create
GET /goats/1 Pais show
GET /goats/1/edit Pais edit
PUT /goats/1 Pais update
DELETE /goats/1 Pais destroy
查看Rails Routing from the Outside in上的guides.rubyonrails.org指南以获取更多信息
答案 1 :(得分: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"}
如果您在之前生成脚手架定义您的变形,则不会更新命名路线。