rails 初心者です。
「先生」と「生徒」のログイン/ログアウト・サインイン機能を作りたいと考えており、deviseで実装してみたのですが、未ログイン時にはサインインとログインを、ログイン時にはログアウトと条件分岐を書きたいときに<% if user_signed_in? %>が使えず、どのように条件分岐をかいたらよいか悩んでいます。
お力をお貸しいただけると嬉しいです。
ruby
1 <!-- 生徒も先生もログインしていないとき--> 2 3 <li><a href="">生徒:サインイン</a></li> 4 <li><a href="">生徒:ログイン</a></li> 5 <li><a href="">先生:サインイン</a></li> 6 <li><a href="">先生:ログイン</a></li> 7 8<!-- 生徒はログインしているが先生はログインしていないとき--> 9 10 11 <li><a href="">ログアウト</a></li> 12 <li><a href="">先生:サインイン</a></li> 13 <li><a href="">先生:ログイン</a></li> 14 15 16<!-- 生徒はログインしていないが先生はログインしているとき--> 17 18 <li><a href="">ログアウト</a></li> 19 <li><a href="">マイページ</a></li> 20 21
ルーティングは以下になります。
ruby
1Prefix Verb URI Pattern Controller#Action 2 new_teacher_session GET /teachers/sign_in(.:format) devise/sessions#new 3 teacher_session POST /teachers/sign_in(.:format) devise/sessions#create 4 destroy_teacher_session DELETE /teachers/sign_out(.:format) devise/sessions#destroy 5 new_teacher_password GET /teachers/password/new(.:format) devise/passwords#new 6 edit_teacher_password GET /teachers/password/edit(.:format) devise/passwords#edit 7 teacher_password PATCH /teachers/password(.:format) devise/passwords#update 8 PUT /teachers/password(.:format) devise/passwords#update 9 POST /teachers/password(.:format) devise/passwords#create 10cancel_teacher_registration GET /teachers/cancel(.:format) devise/registrations#cancel 11 new_teacher_registration GET /teachers/sign_up(.:format) devise/registrations#new 12 edit_teacher_registration GET /teachers/edit(.:format) devise/registrations#edit 13 teacher_registration PATCH /teachers(.:format) devise/registrations#update 14 PUT /teachers(.:format) devise/registrations#update 15 DELETE /teachers(.:format) devise/registrations#destroy 16 POST /teachers(.:format) devise/registrations#create 17 new_student_session GET /students/sign_in(.:format) devise/sessions#new 18 student_session POST /students/sign_in(.:format) devise/sessions#create 19 destroy_student_session DELETE /students/sign_out(.:format) devise/sessions#destroy 20 new_student_password GET /students/password/new(.:format) devise/passwords#new 21 edit_student_password GET /students/password/edit(.:format) devise/passwords#edit 22 student_password PATCH /students/password(.:format) devise/passwords#update 23 PUT /students/password(.:format) devise/passwords#update 24 POST /students/password(.:format) devise/passwords#create 25cancel_student_registration GET /students/cancel(.:format) devise/registrations#cancel 26 new_student_registration GET /students/sign_up(.:format) devise/registrations#new 27 edit_student_registration GET /students/edit(.:format) devise/registrations#edit 28 student_registration PATCH /students(.:format) devise/registrations#update 29 PUT /students(.:format) devise/registrations#update 30 DELETE /students(.:format) devise/registrations#destroy 31 POST /students(.:format) devise/registrations#create 32 home_top GET /home/top(.:format) home#top 33 root GET / home#top 34 rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show 35 rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show 36 rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show 37 update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update 38 rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
お力貸していただけると光栄です。
よろしくお願いします(><)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/05 03:44