link_toで画像とテキストを使ったリンクボタンを作りたい
やりたいこと
<a href="https://sample.com/products/advanced_search" target="_blank">
<img src="images/search.png">
高度な検索
</a>
やり方
link_to ... do ... end
を使う。
ERBの場合
<%= link_to products_advanced_search_path, target: "_blank" do %>
<%= image_tag "search.png" %>
高度な検索
<% end %>
Slimの場合
= link_to products_advanced_search_path, target: "_blank" do
= image_tag "search.png"
| 高度な検索
追記:
@scivola さんからコメントでご指摘を頂いた通り、上記のケースではブロックパラメーターがないので、do
は省略できます。
= link_to products_advanced_search_path, target: "_blank"
= image_tag "search.png"
| 高度な検索
ご指摘ありがとうございます!
Author And Source
この問題について(link_toで画像とテキストを使ったリンクボタンを作りたい), 我々は、より多くの情報をここで見つけました https://qiita.com/ezawa800/items/3f18961e043afcb2cf73著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .