2013-07-23 32 views
0

我似乎無法弄清current_user顯示,編輯和銷燬鏈接的正確路徑。當前用戶編輯並銷燬路徑

這是我曾嘗試:

<% current_user.tasks.each do |task| %> 
    <tr> 
    <td><%= task.completed %></td> 
    <td><%= task.description %></td> 
    <td><%= link_to 'Show', task %></td> 
    <td><%= link_to 'Edit', edit_current_user_task_path(task) %></td> 
    <td><%= link_to 'Destroy', task, method: :delete, data: { confirm: 'Are you sure?' } </td> 
    </tr> 
<% end %> 

任何想法?

回答

0

在您的命令行中運行rake routes並查看可用於您的應用的路由。這裏有一些關於Rails routing的信息。

如果您正在使用資源,並且從外觀上看它們是嵌套的,那麼您需要將current_user以及任務傳遞給show,edit和destroy路徑。

例如,如果你在你的routes.rb文件是這樣的:

resources :users do 
    resources :tasks 
end 

然後,你edit_user_task_path/users/:user_id/tasks/:task_id(通過GET)。

+0

謝謝,請收到此錯誤 未定義的方法'edit_user_task_path」 – Joshua

+0

您是否嘗試過運行'耙routes'?你對編輯任務路徑有什麼看法? – mmichael

+0

似乎現在工作,似乎是我的道路上的一個錯誤,我確實道歉。 – Joshua

0

只需使用普通用戶/任務路徑,沒有理由讓一個特殊的路線:

edit_user_task_path(current_user, task) 
+0

謝謝,繼續收到這個錯誤 未定義的方法'edit_user_task_path' – Joshua

+0

你的意思是替換你的實際路線被稱爲。 – meagar

+0

似乎現在工作,似乎是我的道路上的錯誤,我確實道歉。 – Joshua