Skip to content

Commit

Permalink
Pfp empty (#127)
Browse files Browse the repository at this point in the history
* rails active_storage:install

* rails db:migrate

* partial
  • Loading branch information
adnjoo authored Oct 29, 2024
1 parent a9f0ed9 commit 33b1a1c
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 3 deletions.
Binary file added app/assets/images/default-avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def index
@points = current_user.notes.where(archived: true, completed: true)

@note = Note.new
@user = current_user
end

def new
Expand Down
5 changes: 5 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class User < ApplicationRecord
after_create :send_welcome_email
has_one_attached :profile_image

has_many :notes, dependent: :destroy
# Include default devise modules. Others available are:
Expand All @@ -25,6 +26,10 @@ def self.leaderboard(limit = 10)
.limit(limit)
end

def profile_picture
profile_image.attached? ? profile_image : ActionController::Base.helpers.asset_path("default-avatar.png")
end

private

def send_welcome_email
Expand Down
5 changes: 4 additions & 1 deletion app/views/notes/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<h1 class="text-4xl font-bold uppercase tracking-wide text-black mb-6 border-b-4 border-black">
Your Notes
</h1>
<%= link_to 'Settings', edit_user_registration_path, class: 'text-black hover:underline' %>

<%= render 'shared/profile_picture', user: @user %>

<%= link_to 'Settings', edit_user_registration_path, class: 'text-black hover:underline mt-2 flex' %>
<h3 class="my-8 text-xl font-bold uppercase tracking-wide text-black">
⭐️: <%= @points.count %>
</h3>
Expand Down
5 changes: 4 additions & 1 deletion app/views/notes/leaderboard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
<% @leaderboard.each_with_index do |user, index| %>
<tr class="<%= cycle('bg-gray-200', 'bg-gray-50') %>">
<td class="p-2 border border-black"><%= index + 1 %></td>
<td class="p-2 border border-black"><%= user.username %></td>
<td class="p-2 border border-black flex items-center space-x-2">
<%= render 'shared/profile_picture', user: user %>
<span><%= user.username %></span>
</td>
<td class="p-2 border border-black"><%= user.score %></td>
</tr>
<% end %>
Expand Down
2 changes: 2 additions & 0 deletions app/views/shared/_profile_picture.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- app/views/shared/_profile_picture.html.erb -->
<%= image_tag user.profile_picture, alt: user.username, class: "profile-icon h-8 w-8 flex" %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# This migration comes from active_storage (originally 20170806125915)
class CreateActiveStorageTables < ActiveRecord::Migration[7.0]
def change
# Use Active Record's configured type for primary and foreign keys
primary_key_type, foreign_key_type = primary_and_foreign_key_types

create_table :active_storage_blobs, id: primary_key_type do |t|
t.string :key, null: false
t.string :filename, null: false
t.string :content_type
t.text :metadata
t.string :service_name, null: false
t.bigint :byte_size, null: false
t.string :checksum

if connection.supports_datetime_with_precision?
t.datetime :created_at, precision: 6, null: false
else
t.datetime :created_at, null: false
end

t.index [ :key ], unique: true
end

create_table :active_storage_attachments, id: primary_key_type do |t|
t.string :name, null: false
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
t.references :blob, null: false, type: foreign_key_type

if connection.supports_datetime_with_precision?
t.datetime :created_at, precision: 6, null: false
else
t.datetime :created_at, null: false
end

t.index [ :record_type, :record_id, :name, :blob_id ], name: :index_active_storage_attachments_uniqueness, unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end

create_table :active_storage_variant_records, id: primary_key_type do |t|
t.belongs_to :blob, null: false, index: false, type: foreign_key_type
t.string :variation_digest, null: false

t.index [ :blob_id, :variation_digest ], name: :index_active_storage_variant_records_uniqueness, unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end

private
def primary_and_foreign_key_types
config = Rails.configuration.generators
setting = config.options[config.orm][:primary_key_type]
primary_key_type = setting || :primary_key
foreign_key_type = setting || :bigint
[ primary_key_type, foreign_key_type ]
end
end
33 changes: 32 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 33b1a1c

Please sign in to comment.