Help us understand the problem. What is going on with this article?

link_toで画像とテキストを使ったリンクボタンを作りたい

やりたいこと

こんな感じの画像+テキストなボタンを作りたい。
スクリーンショット 2017-10-19 17.49.14.png

<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"
  | 高度な検索

ご指摘ありがとうございます!

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした