I'm making a list of promotions where each should be deleteable. In the view, for each promotion, I've made a button_to button that should run the delete action in the controller when it is clicked. However, all but the FIRST button work correctly. In other words, the first button doesn't work.
in the promotions controller
def delete
flash[:success] = 'Your promotion has been successfully deleted!'
redirect_to('/promotions')
end
in the promotions view
<% @promotions.each do |p| %>
<tr>
<td>
.
.
.
.
</td>
<td> <%= button_to "Delete" , promotions_delete_path(params: {promo_code: p.promo_code }),
method: :post, class: "btn btn-danger btn-xs" %></td>
<% end %>
I really don't understand why this is happening. Every button but the first reloads the page and renders the flash successfully. The same thing was happening when I attempted to use the javascript confirm with it - it would work for all but the first, so I removed the confirm to see if anything changed - but I still have this issue. I also tried deleting some promotions through the controller and testing the new 'first' button - it doesn't matter what the promotion is, the first button in the list doesn't work. Any help would be appreciated!