I have an inbox table of emails. In each row there is a delete button: <%=link_to 'Delete', e开发者_运维知识库mail, :method => :delete, :confirm => 'Are you sure you want to delete this e-mail?' %>
Note: email here is the email object passed to page.
Now. I want to have a check box in each row, and a common delete button at the bottom. I put the checkbox in each row in as: <%= check_box_tag('email', email)%>
I don't know how to go about doing a common Delete button at the bottom.
Thanks
Just wrap this in a form (say multi_delete), process the checked email ids passed to the action.
You will need to modify this but generally:
#multi_delete action to be defined in config/routes.rb
#in your view
= form_tag(:action => :multi_delete) do
- @emails.each do |email|
= check_box_tag('emails[]', email.id)
= submit_tag('Delete', :confirm => "Go for it?")
#in your controller
def multi_delete
Email.destroy_all("id IN ?", params[:emails])
redirect_to :action => "index"
end
精彩评论