问题描述
如何使公共用户个人资料?我使用Devise,只有/ user /。用户只能看到他的个人资料,我想要/ user / user_id。
How to make public user profiles? I use Devise and only have /user/. User can see only his profile, I want to make /user/user_id.
user_id - 公共用户个人资料。
user_id - public user profile.
推荐答案
要使用 devise
创建公开个人资料,请确保您已设置路线,如
To make a public profile using devise
, make sure you have a route set up like
resources :users
确保您设置了一个控制器操作来处理显示资源。如果没有,创建一个控制器 users_controller.rb
并给它一个类定义以及一个show方法。
and make sure you have a controller action set up to handle the show resource. If not, create a controller users_controller.rb
and give it a class definition, along with a show method.
class UsersController < ApplicationController
def index
@users = User.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @users }
end
end
def show
@user = User.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @user }
end
end
end
下一页浏览 / users / 1
或 / users / 2
(如果您有两个用户设置),您应该看到两个配置文件。要将它们设置为私有,您应该在控制器操作中执行以前的过滤,根据 param [:user_id]
检查current_user标识。
Next browse to /users/1
or /users/2
(if you have two users set up) and you should see both profiles. To set them to private, you should do a before filter in the controller action, checking the current_user id against the param[:user_id]
.
这篇关于公共用户个人资料? Ruby on Rails + Devise的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!