Skip to content

Commit

Permalink
[#9]Added replies to seeds.rb and fixed spacing issue on article pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmckissock committed Jun 27, 2024
1 parent ca69661 commit 333d91a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
2 changes: 0 additions & 2 deletions app/views/articles/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
<h2>Comments</h2>
<ul>
<% @comments.each do |comment| %>
<li>
<%= render_comment_tree(comment) %>
</li>
<% end %>
</ul>
29 changes: 15 additions & 14 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# This file should ensure the existence of records required to run the application in every environment (production,
# development, test). The code here should be idempotent so that it can be executed at any point in every environment.
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
#
# Example:
#
# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name|
# MovieGenre.find_or_create_by!(name: genre_name)
# end
# Clear existing records
User.destroy_all
Article.destroy_all
Comment.destroy_all
Article.destroy_all
User.destroy_all

# Create users
users = [
Expand All @@ -27,7 +17,6 @@
end
end

# Ensure users are created before creating articles
users = User.all

# Create articles and associate them with users
Expand All @@ -42,10 +31,22 @@
articles = Article.all

# Create comments
90.times do |i|
60.times do |i|
Comment.create!(
text: "Sample Comment #{i + 1}",
article: articles.sample,
user: users.sample
)
end

comments = Comment.all
#Create replies to comments
90.times do |i|
comment = comments.sample
Comment.create!(
text: "Sample Reply #{i + 1}",
article: comment.article,
user: users.sample,
parent_id: comment.id
)
end

0 comments on commit 333d91a

Please sign in to comment.