Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

10
7

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.

[Rails] link_toをボタンにして、別タブで表示する方法

Last updated at Posted at 2019-01-18

##前提

DBにTwitterのURLの内容が保存されている

##やりたいこと

Twitterのiconボタンを押すと、別タブでTwitterページを表示出来るようにする。

##手順
###①アイコン設置
Bootstrap-social をダウンロードし下記コードを追加


<i class="btn btn-social-icon btn-twitter"><span class="fab fa-twitter fa-fw"></span></i>

###②リンクをつける

<%= link_to @user.twitter_url do %>
  <i class="btn btn-social-icon btn-twitter"><span class="fab fa-twitter fa-fw"></span></i>
<% end %>

###③別タブで表示するコードを追加
別タブで表示させるため、target: :_blank を追加

<%= link_to @user.twitter_url, target: :_blank do %>
  <i class="btn btn-social-icon btn-twitter"><span class="fab fa-twitter fa-fw"></span></i>
<% end %>

##結論
上記のコードを実行すると、ボタンをクリックすることで別タブでリンクのページに飛んだ。

10
7
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
10
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?