0

这是路线的相关部分:

resources :photos, :path => '', :only => [:show, :new, :create, :destroy, :edit] do
  ...
end

我被添加到视图中删除照片的链接:

  <%= button_to 'Delete', @photo, :method => :delete, :confirm => 'Are you sure?' %>

但是这个视图返回错误:

undefined method `photo_path' for #<#<Class:0x007faef8172060>:0x007faef87a7908>

destroy方法是脚手架生成的方法。我有什么问题?

编辑: rake routes输出:

                root           /                                      photos#index
              search GET       /search(.:format)                      photos#search
      voteup_user_photo GET    /:user_id/:id/voteup(.:format)         photos#voteup
    votedown_user_photo GET    /:user_id/:id/votedown(.:format)       photos#votedown
            user_photos POST   /:user_id(.:format)                    photos#create
         new_user_photo GET    /:user_id/new(.:format)                photos#new
        edit_user_photo GET    /:user_id/:id/edit(.:format)           photos#edit
             user_photo GET    /:user_id/:id(.:format)                photos#show
                     DELETE    /:user_id/:id(.:format)                photos#destroy
4

1 回答 1

3

看来您有一个嵌套路由(路径需要:user_id:id)。尝试显式传递路径参数:

button_to 'Delete', { :user_id => @user.id, :id => @photo.id }, :method => :delete, :confirm => 'Are you sure?'

如果这不起作用,您可能还需要:action在选项哈希中包含 。

于 2013-01-27T14:29:40.383 回答