asciinema.org/app/controllers/users_controller.rb

40 lines
902 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
2015-04-02 09:45:39 +00:00
authorize current_user
render locals: { page: UserEditPagePresenter.new(current_user) }
2012-04-09 12:42:22 +00:00
end
def update
2015-04-02 09:45:39 +00:00
authorize current_user
user = User.find(current_user.id)
2013-10-23 08:00:26 +00:00
2015-04-02 09:45:39 +00:00
if user.update_attributes(update_params)
redirect_to profile_path(user), notice: 'Account settings saved.'
2013-10-23 08:00:26 +00:00
else
2015-04-02 09:45:39 +00:00
render :edit, status: 422, locals: { page: UserEditPagePresenter.new(user) }
2013-10-23 08:00:26 +00:00
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