tap/app/controllers/user_avatar_controller.rb
2015-03-20 04:54:44 +01:00

35 lines
664 B
Ruby

class UserAvatarController < ApplicationController
before_action :authenticate_session_user!
def new
end
def create
if @user.update_attributes(user_params)
flash[:success] = "Your profile is complete. You are now logged in."
sign_in_and_redirect @user
else
render 'new'
end
end
def destroy
reset_session
redirect_to root_path
end
private
def authenticate_session_user!
redirect_to root_path unless session[:id]
@user = User.find_by session[:id]
unless @user
reset_session
redirect_to root_path
end
end
def user_params
params.require(:user).permit(:avatar)
end
end