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 - public user profile.
To make a public profile using devise
, make sure you have a route set up like
resources :users
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
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]
.