I have following code which delete multiple blogposts using checkboxes but when the user clicks on the "Delete Selected" without selecting any blogpost, it gives error. How to make sure the button stays disable or shows a popup error that no selection has been made ? To visualize, here is how my multi delete looks (https://i.stack.imgur.com/P80OG.png)
routes.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