2011-01-13 45 views
1

我正在嘗試向我的RoR3應用程序添加一個新頁面,該頁面應顯示用戶帳戶的刪除確認。它應該匹配'ROOT_RAILS/controllers/accounts_controller.rb'中的'destroy'動作。使用Ruby on Rails進行刪除確認頁面3

在這個時候我的問題發生在創建一個「link_to」這個頁面,但也許我錯了某處,我的工作還沒有完成。

所以,我做了什麼,就是:

  1. 我創造了 'ROOT_RAILS /視圖/ accouns/delete.html.erb' 文件。

  2. 我更新像這樣的routes.rb:

    resources :accounts do 
        collection do 
        get 'delete' 
        post 'delete' 
        end 
    end 
    

我不知道下一個步驟,但現在如果我嘗試插入此代碼

<%= link_to 'Delete', delete_account_path(@current_account) %> 

在我看來,我會得到這個錯誤:

undefined method `delete_account_path' for #<#<Class:0x00...> 

我該怎麼辦?


此 「的link_to」 的作品,但是,當然,也不會讓我想什麼:

<%= link_to 'Delete', delete_users_accounts_path %> 

回答

4

嘗試以下操作:

的config/routes.rb中:

resources :accounts do 
    get :delete, :on => :member 
end 

在刪除頁面之前的視圖中:

<%= link_to 'Delete', delete_account_path(@current_account) %> 

在刪除視圖(這將調用需要在控制器的破壞方法):

<%= link_to 'Delete', @current_account, :confirm => "Are you sure?", :method => :delete %> 
相關問題