Rails/Devise - How to show registration informatio

2019-05-27 10:16发布

问题:

I installed Devise today and everything works fine so far. The only thing devise seems not to offer is a 'registration#show' action, which displays the user information (instead of the registration edit page). I tried to override the registrations-controller, but get the error: 'Unknown action-AbstractController::ActionNotFound' for all actions on this controller. Does anybody know how to display the profile information? Thanks!

class RegistrationsController < Devise::RegistrationsController
  def new
    super
  end

  def create
    super
  end

  def show
  end

  def update
    super
  end
end 

回答1:

I would try to make a new controller based on my authentication model, let's say my authentication model is User. Just create a new controller and make a show page. Something like this should work.

class UsersController < ApplicationController
  def show
    @user = User.find(params[:id])
    # If this show page is only for the currently logged in user change it to @user = current_user
  end
end

Now simply add a view where you list the attributes you want to see and you should be done :)



回答2:

Infact devise by-itself offers a great way to customize it.

try running :-

 "rails generate devise_views" or in newer version of devise try the below    
 "rails generate devise:views" .

This will generate all the views, which you can edit , customise and set route to.
Try this link http://asciicasts.com/episodes/210-customizing-devise for more info.