如何使link_to绑定整个div而非仅文本触发点击事件?
Got it, let's adjust your code so clicking anywhere on that div fires the post request instead of just the "Boeken naar afas" text. Here are two solid approaches using Rails conventions:
Option 1: Wrap the Div in a Block link_to
This is the most straightforward Rails way—we'll replace your div with a link_to block that includes all your existing classes, and wraps the inner content. This makes the entire area clickable:
= link_to update_bookkeeping_claims_claim_manager_path(@claim_manager), method: :post, class: 'col-sm-6 col-md-5 col-lg-3 item ibox-title import' .box.boxBatenmanager .boxInsite.boxTop %i.fa.fa-exclamation-circle <!-- Keep all your original inner content here, including the "Boeken naar afas" text -->
Note: If you need to keep the move() function
If that original onclick="move()" is still necessary, just add it to the link_to attributes:
= link_to update_bookkeeping_claims_claim_manager_path(@claim_manager), method: :post, class: 'col-sm-6 col-md-5 col-lg-3 item ibox-title import', onclick: 'move();' .box.boxBatenmanager .boxInsite.boxTop %i.fa.fa-exclamation-circle <!-- Original inner content -->
Option 2: Use Rails UJS with Data Attributes
If you prefer to keep the div element instead of using an anchor tag, you can use Rails UJS (Unobtrusive JavaScript) to handle the click event. This requires that rails-ujs is loaded on your page (it's included by default in most Rails setups):
.col-sm-6.col-md-5.col-lg-3.item.ibox-title.import{ data: { remote: true, method: :post, url: update_bookkeeping_claims_claim_manager_path(@claim_manager) }, onclick: 'move();' # Keep this if you still need the `move()` function } .box.boxBatenmanager .boxInsite.boxTop %i.fa.fa-exclamation-circle <!-- Original inner content -->
This tells Rails UJS to listen for clicks on the div, then send a POST request to your specified path.
Either approach will make the entire div clickable and trigger the desired action. Pick whichever fits your styling and structure needs best!
内容的提问来源于stack exchange,提问作者akin

