0

I have an index page of elements, and I'm trying to implement a "Delete" button that will send a delete request to the controller with a list of the elements user has checked. So far I've done the following

#routes.rb
resources :messages, :except=>[:update,:edit] do
  member do
   delete :delete_all
  end
end      

#index.html.haml
=button_to "Delete", {:controller=>"messages", :action => "delete_all"}, :method=>"delete"
...
=check_box "message", "mark"

#messages_controller.rb
def delete_all
  ....
end

I've been trying to do it RESTfully, but I've come across routing errors and other tricky problems. Like, for instance, when I used pure AJAX I come across the problem with the before_filter that wants to authenticate the user, and it doesn't let my request through.

Can anyone explain to me what I need to do? How do I implement this button?

4
  • Could you explain how that situation isn't working for you now? Commented Mar 25, 2011 at 6:56
  • Sorry. The code above throws "No route matches {:controller=>"messages", :action=>"delete_all"}" Commented Mar 25, 2011 at 7:00
  • Try using collection do for the route, since this is how you use it in your view (without an :id). Commented Mar 25, 2011 at 7:04
  • @wukerplank: That worked. Thank you. I have another question, but I'll ask it as another post. (If you submit this as an answer I can accept it as correct.) Commented Mar 25, 2011 at 7:21

1 Answer 1

1

Try using collection do for the route, since this is how you use it in your view (without an :id).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.