Reputation: 315
I am trying to do a canceled logic around a button when the item is sent, the button will be disabled.
if order.sent?
else
order.cancel
respond_to do |format|
format.html { redirect_to request.referer.include? "cancel" ? request.referer : order_path(order.shopify_id), notice: 'Order cancelled successfully!' }
end
end
end
<div class="card-body">
<%= link_to 'Cancel', order_path(@order.shopify_id), method: :delete, class: 'btn btn-danger' %>
</div>
I was wondering should I do it the if statement with the view or controller?
Upvotes: 1
Views: 65
Reputation: 1227
<div class="card-body">
<%= link_to 'Cancel', order_path(@order.shopify_id), method: :delete, class: 'btn btn-danger', disabled: @order.sent? %>
</div>
Change your view code to this. It will disable it when it's already sent.
Upvotes: 1