参考:http://www.iteye.com/topic/220360
自动生成的fish_path会有index和instance path的冲突。
你可以使用fish_index_path和 fish_path(@fish)来区别。
(1) 声明单复数形式,如果符合Rails已声明的规则,那么不需要再声明。
可以在%RAILS_APP_ROOT%/config/routes.rb中定义,使用singular参数,也可以 在%RAILS_APP_ROOT%/config/initializers/inflections.rb文件中声明,后者好像是官方推崇的方式。
默认规则文件为:
%RUBY_ROOT_PATH%\lib\ruby\gems\1.8\gems\activesupport-2.1.0\lib\active_support\inflections.rb
不过我用的是修改routes.rb的方法:
map.resources :news, :singular => 'news'
(2) 修改modelname_controlles.rb, /new.html.erb, /show.html.erb, /edit.html.erb 中的modelname _path 为modelname _index_path
(3) 修改new.html.erb 中的
<% form_for(@modelname) do |f| %>
为
<% form_for( @modelname , :url => modelname_index_path) do |f| %>