Making a delete confirmation page using Ruby on Rails 3
I am trying to add a new page to my RoR3 application that should display a delete confirmation of a user account. It should match the 'destroy' action in 'ROOT_RAILS/controllers/accounts_controller.rb'.
At this time my problem occurs on creating a "link_to" this page, but maybe I am wrong somewhere and my work is not completed yet.
So, what I made, is:
I created the 'ROOT_RAILS/views/accouns/delete.html.erb' file.
I updated the routes.rb like this:
resources :accounts do collection do get 'delete' post 'delete' end end
I don't know the next steps, but now if I try to insert this code
<%= link_to 'Delete', delete_account_path(@current_account) %>
in my views, I will get this error:
undefined method `delete_account_path' for #<#<Class:0x00...>
What I have to do?
This 开发者_开发知识库"link_to" works, but, of course, doesn't make what I would like:
<%= link_to 'Delete', delete_users_accounts_path %>
Try the following:
config/routes.rb:
resources :accounts do
get :delete, :on => :member
end
In the view before the delete page:
<%= link_to 'Delete', delete_account_path(@current_account) %>
In the delete view(this will invoke the destroy method in your controller):
<%= link_to 'Delete', @current_account, :confirm => "Are you sure?", :method => :delete %>
精彩评论