使用Devise创建“Users”显示页面 [英] Creating a `Users` show page using Devise

查看:136
本文介绍了使用Devise创建“Users”显示页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个用户显示页面(将用作配置文件页面),但是对于如何使用Devise来说,这是困惑的。看起来好像Devise带有任何一种 show 定义 - 是否有任何方式可以访问Devise正在实施的控制器,以便使一个或者我有覆盖他们

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 Devise comes with any sort of show definition - is there any way I can access the controllers Devise is implementing in order to make one or do I have to override them?

推荐答案

您应该生成 users_controller ,继承自 application_controller 并定义您的自定义 show 方法。不要忘了为它创建一个视图和路由。
例如:

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]

这篇关于使用Devise创建“Users”显示页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆