我正在尝试向我的RoR3应用程序添加一个新页面,该应用程序应显示用户帐户的删除确认。它应匹配'ROOT_RAILS / controllers / accounts_controller.rb'中的'destroy'操作。
此时我的问题出现在创建“link_to”这个页面上,但也许我错了,我的工作尚未完成。
所以,我所做的是:
我创建了'ROOT_RAILS / views / accouns / delete.html.erb'文件。
我像这样更新了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 %>
答案 0 :(得分:4)
尝试以下方法:
配置/ routes.rb中:
resources :accounts do
get :delete, :on => :member
end
在删除页面之前的视图中:
<%= link_to 'Delete', delete_account_path(@current_account) %>
在删除视图中(这将调用控制器中的destroy方法):
<%= link_to 'Delete', @current_account, :confirm => "Are you sure?", :method => :delete %>