Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

メンターの関連著書の表示を調整・開発環境用のデータを追加しました #5813

Merged
merged 5 commits into from
Nov 25, 2022
Merged
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
2 changes: 1 addition & 1 deletion app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class WelcomeController < ApplicationController
layout 'welcome'

def index
@mentors = User.with_attached_profile_image.mentor.includes(authored_books: { cover_attachment: :blob }).order(:created_at)
@mentors = User.mentors_sorted_by_created_at
end

def pricing; end
Expand Down
2 changes: 2 additions & 0 deletions app/models/authored_book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ class AuthoredBook < ApplicationRecord
in: %w[image/png image/jpg image/jpeg image/gif],
message: 'はPNG, JPG, GIF形式にしてください'
}

scope :sorted, -> { order(created_at: :desc) }
end
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ class User < ApplicationRecord
}
scope :year_end_party, -> { where(retired_on: nil) }
scope :mentor, -> { where(mentor: true) }
scope :mentors_sorted_by_created_at, lambda {
with_attached_profile_image
.mentor
.includes(authored_books: { cover_attachment: :blob })
.order(:created_at)
}
scope :working, lambda {
active.where(
adviser: false,
Expand Down
2 changes: 1 addition & 1 deletion app/views/welcome/_mentor.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ section.welcome-member.a-card
- if mentor.authored_books.present?
.welcome-member-books
ul.welcome-member-books__items
- mentor.authored_books.each do |authored_book|
- mentor.authored_books.sorted.each do |authored_book|
Copy link
Contributor

Choose a reason for hiding this comment

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

すっきりしましたね!

- if authored_book.cover.attached?
li.welcome-member-books__item
= link_to authored_book.url, target: :_blank, rel: 'noopener noreferrer', class: 'welcome-member-books__item-link' do
Expand Down
17 changes: 17 additions & 0 deletions db/fixtures/authored_books.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
authored_book1:
user: mentormentaro
title: Rubyのひみつ
url: https://www.example.com
created_at: "2022-03-01 00:00:01"

authored_book2:
user: mentormentaro
title: 3ステップでしっかり学ぶ ruby入門
url: https://www.amazon.co.jp/dp/4774195022/
created_at: "2022-02-01 00:00:01"

authored_book3:
user: mentormentaro
title: スラスラ読める Rubyふりがなプログラミング (ふりがなプログラミングシリーズ)
url: https://www.amazon.co.jp/dp/4295005908/
created_at: "2022-01-01 00:00:01"
Binary file added db/fixtures/files/authored_books/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added db/fixtures/files/authored_books/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added db/fixtures/files/authored_books/3.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 db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
organizers
hibernations
footprints
authored_books
]

ActiveRecord::FixtureSet.create_fixtures 'db/fixtures', tables
Expand Down
9 changes: 9 additions & 0 deletions lib/bootcamp/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def attachment
attach_user_avatar!
attach_company_logo!
attach_book_cover!
attach_authored_book_cover!
end

private
Expand Down Expand Up @@ -54,6 +55,14 @@ def attach_book_cover!
book.cover.attach(io: File.open(path), filename: filename) if File.exist?(path)
end
end

def attach_authored_book_cover!
AuthoredBook.order(:created_at).each_with_index do |authored_book, i|
filename = "#{i + 1}.png"
path = Rails.root.join("#{fixtures_dir}/fixtures/files/authored_books/#{filename}")
authored_book.cover.attach(io: File.open(path), filename: filename) if File.exist?(path)
end
end
end
end
end