0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

link_toの使用方法(電話番号、メール、URL等のリンク化)

Posted at

参考リンク

Railsドキュメント
MDN

オリジナルアプリ内での使用例

電話番号 ver.

app/views/courts/show.html.erb
<p>
  <strong>TEL:</strong>
  <%= @court.tel %>
</p>

app/views/courts/show.html.erb
<p>
  <strong>TEL:</strong>
  <%= link_to @court.tel, "tel:" + @court.tel %>
</p>

に変更する。

  • tel:はstringにしなければいけないので、””で囲む。
  • +を使うことでstring同士の足し算ができる。

メール ver.

app/views/courts/show.html.erb
<p>
  <strong>EMAIL:</strong>
  <%= @court.store_email %>
</p>

app/views/courts/show.html.erb
<p>
  <strong>EMAIL:</strong>
  <%= link_to @court.store_email, "mailto:@court.store_email" %>
</p>

に変更する。

URL ver.

app/views/courts/show.html.erb
<p>
  <strong>URL:</strong>
  <%= @court.url %>
</p>

app/views/courts/show.html.erb
<p>
  <strong>URL:</strong>
  <%= link_to @court.url, @court.url, { :target => "_blank" } %>
</p>

に変更する。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?