Creating a `Users` show page using Devise

前端 未结 4 1086
失恋的感觉
失恋的感觉 2020-12-07 09:37

I\'m trying to create a User show page (that will function as a profile page) but am confused about how to do this with Devise. It doesn\'t seem as though Devi

4条回答
  •  醉酒成梦
    2020-12-07 10:32

    You should generate a users_controller which inherits from application_controller and define there your custom show method. Don't forget to create a view and routes for it. Ex:

    #users_controller.rb
    def show
      @user = User.find(params[:id])
    end
    
    #in your view
    <%= @user.name %>
    
    #routes.rb
    match 'users/:id' => 'users#show', via: :get
    # or 
    get 'users/:id' => 'users#show'
    # or
    resources :users, only: [:show]
    

提交回复
热议问题