User profile pages with devise - Routing to show action

后端 未结 3 1072
执笔经年
执笔经年 2020-12-31 21:33

Authentication with devise and a separate controller (Users) that is a single \'show\' action

class UsersController < ApplicationController
#before_filter         


        
相关标签:
3条回答
  • 2020-12-31 21:59

    If you want to see the current logged in users profile make sure you are logged in.

    add the before_filter :authenticate_user! in users controller.

    Then in header link <li><%= link_to "Profile", current_user %></li>

    0 讨论(0)
  • 2020-12-31 22:00

    I think this may help you.

    In "Rails routing from the Outside in",

    For example, you would like /profile to always show the profile of the currently logged in user. In this case, you can use a singular resource to map /profile (rather than /profile/:id) to the show action.

    match "profile" => "users#show", :as => 'profile'
    
    <li><%= link_to "Profile", profile_path %></li>
    

    That is for private profile page.

    Since the public profile page will be different to private profile page, I would create a profiles controller to show public profiles.

    0 讨论(0)
  • 2020-12-31 22:05

    You just need to pass User instance as a parameter to link_to if you want it to link to given user's show page. So if you want to link to currently logged in user's profile in Devise, you just need:

    <li><%= link_to "Profile", current_user %></li>
    
    0 讨论(0)
提交回复
热议问题