Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
controller_users
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update]
before_action :require_same_user, only: [:edit, :update]
def index
@user = User.all
end
def show
@user = User.find(params[:id])
end
def new
@user = User.new
end
def create
@user = User.new(user_params)
if @user.save
flash[:notice] = "You are registered."
redirect_to root_path
else
render :new
end
end
def edit
@user = User.find(params[:id])
end
def update
if @user.update(user_params)
flash[:notice] = "profile updated"
redirect_to root_path
else
render :edit
end
end
def write_private_message
@private_message = PrivateMessage.new
@user = User.find(params[:id])
end
def send_private_message
@private_message = PrivateMessage.new(private_message_params)
@notification = Notification.create(notificationable_type: @private_message, user: current_user, notification: params[:notification])
redirect_to user_path
end
private
def private_message_params
params.require(:private_message).permit(:sender_uid, :receiver_uid, :subject, :body)
end
def user_params
params.require(:user).permit(:first_name, :last_name, :password)
end
def set_user
@user = User.find(params[:id])
end
def require_same_user
if current_user != @user
flash[:error] = "You're not allowed to do that"
redirect_to root_path
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.