Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby 3.1.4
Binary file added app/assets/images/default_avatar.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
class ProfilesController < ApplicationController
def show
before_action :authenticate_user!
before_action :set_user

def show; end

private

def set_user
@user = current_user
end
end
13 changes: 13 additions & 0 deletions app/helpers/profile_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move in decorator?


# Helper methods for the User Profile
module ProfileHelper
def avatar_for(user, classes: "h-12 w-12 rounded-full" )
user_name = user.name || "User"
if user.avatar.attached?
image_tag user.avatar, alt: user_name, class: classes
else
image_tag 'default_avatar.jpeg', alt: user_name, class: classes
end
end
end
16 changes: 16 additions & 0 deletions app/models/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,20 @@ class Profile < ApplicationRecord
belongs_to :user

has_one_attached :picture

before_validation :set_default_picture, on: :create

alias owner user
alias avatar picture

private

def set_default_picture
return if picture.attached?

picture.attach(io: File.open(Rails.root.join('app', 'assets', 'images', 'default_avatar.jpeg')),
filename: 'default_avatar.jpeg',
content_type: 'image/jpeg')
end

end
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class User < ApplicationRecord

after_create :new_profile

delegate :name, :address_1, :address_2, :city, :state, :country, :avatar, to: :profile

def new_profile
self.profile = Profile.new
save!
Expand Down
6 changes: 3 additions & 3 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
<button data-header-target="openUserMenu" type="button" class="relative flex rounded-full bg-white focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2" id="user-menu-button" aria-expanded="false" aria-haspopup="true">
<span class="absolute -inset-1.5"></span>
<span class="sr-only">Open user menu</span>
<% if user_signed_in? && current_user.profile.picture.present? %>
<%= image_tag current_user.profile.picture, class:"h-8 w-8 rounded-full" %>
<% if user_signed_in? %>
<%= avatar_for(current_user, classes: "h-8 w-8 rounded-full") %>
<% else %>
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down Expand Up @@ -83,7 +83,7 @@
>
<!-- Active: "bg-gray-100", Not Active: "" -->
<% if user_signed_in? %>
<%= link_to "Account", profile_path(current_user.id) , class:"block px-4 py-2 text-sm text-gray-700", role:"menuitem", tabindex:"-1" %>
<%= link_to "Account", profile_path, class:"block px-4 py-2 text-sm text-gray-700", role:"menuitem", tabindex:"-1" %>
<%= link_to "Wishlist", wishlists_path, class:"block px-4 py-2 text-sm text-gray-700", role:"menuitem", tabindex:"-1" %>
<%= link_to "Log out", destroy_user_session_path, data: { "turbo-method": :delete }, class:"block px-4 py-2 text-sm text-gray-700", role:"menuitem", tabindex:"-1" %>
<% else %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/properties/_reviews.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@
<% property.reviews.limit(6).each do |review| %>
<div class="flex flex-col">
<div class="flex items-center">
<%= image_tag review.user.profile.picture, alt: review.user.profile.name, class:"h-12 w-12 rounded-full" %>
<%= avatar_for(review.user) %>
<div>
<p class="text-base text-gray-900 ms-4"><%= review.user.profile.name %></p>
<p class="text-xs text-gray-900 ms-4"><%= review.user.profile.city %>, <%= review.user.profile.country %></p>
<p class="text-base text-gray-900 ms-4"><%= review.user.name %></p>
<p class="text-xs text-gray-900 ms-4"><%= review.user.city %>, <%= review.user.country %></p>
</div>
</div>
<div class="mt-2 flex items-center">
Expand Down
6 changes: 3 additions & 3 deletions app/views/properties/_reviews_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@
<% content_params[:property].reviews.each do |review| %>
<div class="flex flex-col py-4">
<div class="flex items-center">
<%= image_tag review.user.profile.picture, alt: review.user.profile.name, class:"h-12 w-12 rounded-full" %>
<%= avatar_for(review.user) %>
<div>
<p class="text-base text-gray-900 ms-4"><%= review.user.profile.name %></p>
<p class="text-xs text-gray-900 ms-4"><%= review.user.profile.city %>, <%= review.user.profile.country %></p>
<p class="text-base text-gray-900 ms-4"><%= review.user.name %></p>
<p class="text-xs text-gray-900 ms-4"><%= review.user.city %>, <%= review.user.country %></p>
</div>
</div>
<div class="mt-2 flex items-center">
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_profile_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<li>
<ul role="list" class="-mx-2 space-y-1">
<li>
<%= link_to profile_path(current_user.id), class:"#{ controller_name == 'profiles' ? 'bg-gray-50 text-primary' : 'text-gray-700 hover:text-primary hover:bg-gray-50'} group flex gap-x-3 rounded-md p-2 text-sm leading-6 font-semibold" do %>
<%= link_to profile_path, class:"#{ controller_name == 'profiles' ? 'bg-gray-50 text-primary' : 'text-gray-700 hover:text-primary hover:bg-gray-50'} group flex gap-x-3 rounded-md p-2 text-sm leading-6 font-semibold" do %>
<svg class="h-6 w-6 shrink-0 <%= controller_name == 'profiles' ? 'text-primary' : 'group-hover:text-primary' %>" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="M2.25 12l8.954-8.955c.44-.439 1.152-.439 1.591 0L21.75 12M4.5 9.75v10.125c0 .621.504 1.125 1.125 1.125H9.75v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21h4.125c.621 0 1.125-.504 1.125-1.125V9.75M8.25 21h8.25" />
</svg>
Expand Down
12 changes: 6 additions & 6 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
resources :wishlists, only: [:create, :destroy]
end

resources :properties, only: [:show] do
resources :bookings, only: [:new]
resources :properties, only: :show do
resources :bookings, only: :new
end

resources :booking_payments, only: [:create]
resources :booking_payments, only: :create

get "booking_payments/success", to: "booking_payments#success"

resources :wishlists, only: [:index]
resources :wishlists, only: :index

resources :profiles, only: [:show]
resource :profile, only: :show

resources :reservations, only: [:show]
resources :reservations, only: :show
end
3 changes: 3 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'open-uri'

description = <<-DESCRIPTION
<div>Explore the nature and art oasis at our unique property. The living room, a cozy masterpiece, and the fully equipped kitchen are ideal for cooking and entertaining. Step outside to our garden patio, unwind, and enjoy morning birdsong. Tastefully decorated bedrooms, a powder room, and utility area complete the experience.<br />Note: The property is surrounded by a residential area. Despite initial surroundings, I am sure that, stepping in will fill your mood with joy and happiness.
</div>
Expand Down Expand Up @@ -74,6 +76,7 @@
})

profile.picture.attach(io: pictures[0], filename: profile.name)
# user.avatar.attach(io: URI.parse(Faker::LoremFlickr.image).open, filename: "user_#{user.id}_avatar.jpg")

19.times do |i|
random_user = User.create!(
Expand Down