错误获取路径返回rails 4

时间:2014-04-02 13:31:37

标签: ruby-on-rails-4 routes nested-forms

我正在尝试通过链接访问我的页面库/ new,所以我创建了这个

<%= link_to 'New gallery' new_gallery_path %>

rake routes给出

gallery_index_path   GET     /gallery(.:format)  gallery#index
                     POST    /gallery(.:format)  gallery#create
new_gallery_path     GET     /gallery/new(.:format)  gallery#new
edit_gallery_path    GET     /gallery/:id/edit(.:format)     gallery#edit
gallery_path         GET     /gallery/:id(.:format)  gallery#show
                     PATCH   /gallery/:id(.:format)  gallery#update
                     PUT     /gallery/:id(.:format)  gallery#update
                     DELETE  /gallery/:id(.:format)  gallery#destroy

在我的路线中我有

resources :gallery

我在gallery / new的观点是

<%= nested_form_for @gallery, :html => { :multipart => true} do |f| %>
--content here
<% end %>

每当我点击链接查看此页面我都会

undefined method `galleries_path

有人可以指出我的错误吗?

1 个答案:

答案 0 :(得分:1)

您为resources选择了错误的名称。它应该总是多元化的:

resources :galleries

从这个Rails将正确生成复数和奇异路径。索引为galleries_path,show为gallery_path等等。