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.
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 %>