-
Notifications
You must be signed in to change notification settings - Fork 0
ログインの共通関数
NoguHiro edited this page Feb 11, 2014
·
4 revisions
共通のhelper methodで、current_userという共通関数を作成しています。
利用方法に関しては次のようになります。
//ログインしているか、していないかを確認する場合
<% if current_user %>
ログインしています。
<% else %>
ログインしていません
<% end %>
//ログインしているユーザーの情報を取り出す場合
current_user.id => 現在ログインしているユーザーのIDを抽出する。
current_user.name => 現在ログインしているユーザーの名前を抽出する。
//entry_cards等とリレーションをする場合は、Userオブジェクトを作成する必要がある。
if current_user
@user = User.find(current_user.id)
@user.entry_cards.size //ユーザーが参加しているラリー数の取得
//ユーザーが登録しているラリーをループする。
@user.entry_cards.each do |card|
card.rally.title //ラリー名の取得
card.rally.checkpoints.size //チェックポイント数の取得
end
end