我有以下代码使用复选框删除多个博客文章,但是当用户单击“删除所选”而不选择任何博客文章时,它会出错。如何确保按钮保持禁用状态或显示未进行选择的弹出错误?为了形象化,这里是我的多重删除的样子(http://i.imgur.com/3mfglyI.png)
路线.rb:
resources :blog_posts do
collection do
delete 'destroy_multiple'
end
end
index.html.erb:
<%= form_tag destroy_multiple_blog_posts_path, method: :delete do %>
<table>
...
<td><%= check_box_tag "blog_posts[]", blog_post.id %></td>
...
</table>
<%= submit_tag "Delete selected" %>
<% end %>
blog_posts_controller.rb:
def destroy_multiple
BlogPost.destroy(params[:blog_posts])
respond_to do |format|
format.html { redirect_to blog_posts_path }
format.json { head :no_content }
end
end