Question

I have the following code:

  <% @groups.each do |group| %>
         <button class="btn btn-danger" data-method="destroy" data-confirm="Sure?" type="button">
            <i class="fa fa-trash-o"></i>
         </button> 
   <% end %>

And in my controller:

 def destroy
   @group = Group.find(params[:id])
   respond_to do |format|  
   if @result = @group.destroy  
    format.html
    format.js        
  else  
    format.html 
    format.js
  end  
 end  
end

However, it is not triggering even the confirmation. I've looked at the API regarding UJS, as well as other posts on SO, however, I'm cannot figure out what I am doing wrong here.

Any point in the right direction would be greatly appreciated.

Was it helpful?

Solution

So, here's how I fixed it:

First, I made sure all my resources were defined in the routes file.

resources :groups

Second, this is how I figured out the link_to method:

<%= link_to group, method: :delete, class: 'btn btn-danger', confirm: 'Are you sure?', :remote => true do %>
  <i class="fa fa-trash-o"></i> 
<% end %>

OTHER TIPS

Button won't trigger the form submission, So you have to change it to a tag.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top