Skip to content

Commit

Permalink
development環境でメンターの関連著書の表示する
Browse files Browse the repository at this point in the history
  • Loading branch information
ksmxxxxxx committed Nov 19, 2022
1 parent bc9d48d commit a5fd49d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
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

0 comments on commit a5fd49d

Please sign in to comment.