Skip to content

Commit

Permalink
Add string representation methods and JSON link to account show view
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Nov 27, 2024
1 parent b325786 commit a24f00e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ class Account < ApplicationRecord

before_save :set_sponsors_count

def to_s
login
end

def to_param
login
end

def set_sponsors_count
self.sponsors_count = total_sponsors == 0 ? sponsorships_as_maintainer.count : total_sponsors
self.sponsorships_count = sponsorships_as_funder.count
Expand Down
8 changes: 7 additions & 1 deletion app/views/accounts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
<%= link_to @account.login, @account.html_url, target: :_blank %>
</h1>

<p class='text-muted'>
<small>
<%= link_to 'View JSON Representation', api_v1_account_path(@account), target: :_blank %>
</small>
</p>

<% if @account.data.present? %>
<% if @account.description.present? %>
<p>
Expand All @@ -20,7 +26,7 @@
<% end %>

<ul class='list-unstyled'>
<% ['name', 'location', 'company', 'kind', 'followers', 'following', 'total_stars', 'repositories_count', 'created_at', 'updated_at'].each do |key| %>
<% ['name', 'location', 'company', 'kind', 'followers', 'following', 'total_stars', 'repositories_count', 'created_at', 'updated_at', 'last_synced_at'].each do |key| %>
<% value = @account.data[key] %>
<% next if value.blank? %>
<li>
Expand Down

0 comments on commit a24f00e

Please sign in to comment.