2014-10-02 53 views
1

嘗試顯示銷燬鏈接時出現無方法錯誤。軌道上的紅寶石由於路由而沒有方法錯誤

下面的代碼,以我的觀點

<% @followed_locations.each do |followed_location| %> 
     <tr> 
     <td><%= followed_location.user_id %></td> 
     <td><%= followed_location.location_id %></td> 
     <td><%= link_to 'Show', api_v1_followed_location_path(followed_location) %></td> 
     <td><%= link_to 'Edit', edit_api_v1_followed_location_path(followed_location) %></td> 
     <td><%= link_to 'Destroy', followed_location, method: :delete, data: { confirm: 'Are you sure?' } %></td> 
     </tr> 
    <% end %> 

,這裏是我的,因爲我猜它是與命名空間在我的路線,但我的路線

namespace :api do 
    namespace :v1 do 
    resources :followed_locations do 
     collection do 
     post "by_user_id" 
     post "by_location_id" 
     end 
    end 
    end 
end 

代碼不確定如何解決它,我似乎無法找到任何關於此事的在線信息。謝謝你的幫助!

+1

請包括實際的錯誤,例如,堆棧跟蹤。 – 2014-10-02 19:45:19

+2

刪除路徑是顯示路徑和':delete'方法的組合。在你的情況:'api_v1_followed_location_path(followed_location),方法:: delete' – MrYoshiji 2014-10-02 19:45:40

+0

(但是,它是嵌套的,所以你必須使用完整的資源路徑。) – 2014-10-02 19:48:03

回答

1

試試這個:

<%= link_to "Destory", api_v1_followed_location_path(followed_location), method: :delete, data: { confirm: 'Are you sure?' } %> 
1

因爲如果你有namspaces api和v1,你也需要包含在路徑中。 因此,它應該是這樣的:

<%= link_to 'Destroy', api_v1_followed_location, method: :delete, data: { confirm: 'Are you sure?' } %> 

編輯:代碼中沒有顯示出來,現在固定