The following is a code from my UsersController action. I have a current_user object from a session, and I’d like to use the current user’s ID if none is passed into the action.
def show
id = params[:id]
id = current_user.id if id.blank?
@user = User.find(id)
end
I’m doing this so that, eventually, I can have administrators who can edit other users’ info. That is why I just don’t use @user = User.find(current_user.id).
Thoughts/suggestions? I could probably also do a ternary operator, something like
params[:id].present? ? id = params[:id] : id = current_user.id
but I’m thinking there is probably an even better way.
I prefer this way