Rails/Devise - How to show registration information (not just edit it)

橙三吉。 提交于 2019-12-07 19:30:29

问题


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.



来源:https://stackoverflow.com/questions/4035944/rails-devise-how-to-show-registration-information-not-just-edit-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!