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 1 year has passed since last update.

ログインの有無で処理を変える方法

Posted at

はじめに

user_signed_in?メソッドの利用方法を忘れないために記録する

user_signed_in?メソッドとは

Gemのdeviseを導入しているため、使用できるメソッド。
ログインしているかどうかの判定を行う。

#記載方法
<% if user_signed_in? %>
   <div class="user_nav grid-6">
      <%= link_to "ログアウト", destroy_user_session_path, method: :delete %>
      <%= link_to "投稿する", new_tweet_path, class: "post" %>
   </div>
<% else %>
   <div class="grid-6">
      <%= link_to "ログイン", new_user_session_path, class: "post" %>
      <%= link_to "新規登録", new_user_registration_path, class: "post" %>
   </div>
<% end %>
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?