需求:点击.box.boxAccounts容器跳转页面替代仅点击文本
To make the entire .box.boxAccounts container clickable instead of just the account text, you'll want to use Rails' link_to helper with a block—this lets you wrap the entire container in the anchor tag. Here's how to adjust your Haml code:
.features-boxed .container.boxContainer #myUL.row.features.appFunction.indexBox - @accounts.sort_by(&:name).each do |account| .col-sm-6.col-md-5.col-lg-3.item.icons = link_to account_path(account) do .box.boxAccounts .boxInsiteAccount %i.fa.fa-building.iconSpaceBottom.accountIcon %h3= account.name # Keep any other existing content inside .boxInsiteAccount here
What changed:
- Moved the
link_tocall to wrap the entire.box.boxAccountsdiv instead of just the account name text. - Used the block syntax for
link_to(passing ado...endblock) which generates an<a>tag enclosing all content inside the block. - Ensured the path (
account_path(account)) points correctly to your account show page—adjust this if your route uses a different helper name.
Now, clicking anywhere within the .box.boxAccounts container (icon, text, or empty space inside the box) will trigger navigation to the account's page.
Quick note: If you have other interactive elements (like buttons or nested links) inside .box.boxAccounts, this might cause unexpected behavior since nested anchors aren't valid HTML. But assuming your box only contains static content (icon + account name), this approach works perfectly.
内容的提问来源于stack exchange,提问作者akin

