asciinema.org/app/controllers/users_controller.rb

40 lines
796 B
Ruby
Raw Normal View History

2012-03-04 22:07:45 +00:00
class UsersController < ApplicationController
2013-10-19 16:25:30 +00:00
2012-04-09 12:42:22 +00:00
before_filter :ensure_authenticated!, :only => [:edit, :update]
attr_reader :user
2012-03-04 22:07:45 +00:00
def show
2014-10-05 17:53:00 +00:00
if params[:username]
user = User.for_username!(params[:username])
else
user = User.find(params[:id])
end
2014-06-25 15:35:13 +00:00
render locals: { page: UserPagePresenter.build(user, current_user, params[:page]) }
2012-03-04 22:07:45 +00:00
end
2012-03-05 23:25:21 +00:00
2012-04-09 12:42:22 +00:00
def edit
@user = current_user
2014-07-05 12:59:42 +00:00
authorize @user
2012-04-09 12:42:22 +00:00
end
def update
@user = User.find(current_user.id)
2014-07-05 12:59:42 +00:00
authorize @user
2013-10-23 08:00:26 +00:00
if @user.update_attributes(update_params)
2013-10-23 08:00:26 +00:00
redirect_to profile_path(@user), notice: 'Account settings saved.'
else
render :edit, status: 422
end
2012-04-09 12:42:22 +00:00
end
2012-03-10 13:58:10 +00:00
private
def update_params
params.require(:user).permit(:username, :name, :email, :theme_name)
end
2012-03-04 22:07:45 +00:00
end