diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0669180..834b644 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,14 +1,16 @@ class UsersController < ApplicationController - before_action :set_user, only: %i[show edit update ] + before_action :set_user, only: %i[show edit update update_bio] + before_action :set_user_for_upload, only: [:upload_profile_picture] def index @users = User.all end def show + @friends = @user.friends + @entries = @user.entries end - def edit end @@ -20,14 +22,35 @@ def update end end + def upload_profile_picture + if params[:user][:profile_picture].present? + @user.profile_picture.attach(params[:user][:profile_picture]) + redirect_to @user, notice: 'Profile picture uploaded successfully.' + else + redirect_to @user, alert: 'No picture selected.' + end + end + + def update_bio + @user = current_user + if @user.update(user_params) + redirect_to @user, notice: 'Bio updated successfully.' + else + render :show + end + end private def set_user - @user = User.find_by(id: params[:id]) + @user = current_user + end + + def set_user_for_upload + @user = User.find(params[:id]) end def user_params params.require(:user).permit(:email, :username, :bio, :profile_picture) end -end \ No newline at end of file +end diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 9c48307..6a8f4fa 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,18 +1,94 @@
<%= @user.bio %>
- <% else %> -No bio available.
+<%= entry.text %>
+ <%= entry.created_at.strftime("%B %d, %Y") %> + +
Comments
+<%= comment.text %>
+