문제

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top